Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nimble recursive testing #1019

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Nimble recursive testing
  • Loading branch information
tandy-1000 committed Aug 11, 2022
commit 96ab6e2aa737ff43ef52e0da54b364f17b4d188b
35 changes: 12 additions & 23 deletions src/nimble.nim
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,9 @@ proc installFromDir(dir: string, requestedVer: VersionRange, options: Options,
var filesInstalled: HashSet[string]
iterInstallFiles(realDir, pkgInfo, options,
proc (file: string) =
createDir(changeRoot(realDir, pkgDestDir, file.splitFile.dir))
let dest = changeRoot(realDir, pkgDestDir, file)
filesInstalled.incl copyFileD(file, dest)
createDir(changeRoot(realDir, pkgDestDir, file.splitFile.dir))
let dest = changeRoot(realDir, pkgDestDir, file)
filesInstalled.incl copyFileD(file, dest)
)

# Copy the .nimble file.
Expand Down Expand Up @@ -927,7 +927,7 @@ proc dump(options: Options) =
j[key].add %{
"name": % name,
# we serialize both: `ver` may be more convenient for tooling
# (no parsing needed); while `str` is more familiar.
# (no parsing needed); while `str` is more familiar.
"str": % $ver,
"ver": %* ver,
}
Expand Down Expand Up @@ -1394,11 +1394,10 @@ proc develop(options: var Options) =

proc test(options: Options) =
## Executes all tests starting with 't' in the ``tests`` directory.
## Subdirectories are not walked.
var pkgInfo = getPkgInfo(getCurrentDir(), options)

var
files = toSeq(walkDir(getCurrentDir() / "tests"))
files = toSeq(walkDirRec(getCurrentDir() / "tests", {pcFile, pcLinkToFile}, relative = true))
tests, failures: int

if files.len < 1:
Expand All @@ -1408,7 +1407,8 @@ proc test(options: Options) =
if not execHook(options, actionCustom, true):
raise nimbleError("Pre-hook prevented further execution.")

files.sort((a, b) => cmp(a.path, b.path))
files.sort((a, b) => cmp(a, b))
files = files.map((a) => "tests" / a)

for file in files:
let (_, name, ext) = file.path.splitFile()
Expand All @@ -1422,10 +1422,8 @@ proc test(options: Options) =
# treat run flags as compile for default test task
optsCopy.getCompilationFlags().add(options.action.custRunFlags)
optsCopy.getCompilationFlags().add("-r")
optsCopy.getCompilationFlags().add("--out=" & ("build/" / file.changeFileExt(ExeExt)))
optsCopy.getCompilationFlags().add("--path:.")
let
binFileName = file.path.changeFileExt(ExeExt)
existsBefore = fileExists(binFileName)

if options.continueTestsOnFailure:
inc tests
Expand All @@ -1436,15 +1434,6 @@ proc test(options: Options) =
else:
execBackend(pkgInfo, optsCopy)

let
existsAfter = fileExists(binFileName)
canRemove = not existsBefore and existsAfter
if canRemove:
try:
removeFile(binFileName)
except OSError as exc:
display("Warning:", "Failed to delete " & binFileName & ": " &
exc.msg, Warning, MediumPriority)

if failures == 0:
display("Success:", "All tests passed", Success, HighPriority)
Expand Down Expand Up @@ -1988,10 +1977,10 @@ proc doAction(options: var Options) =
# fallback logic.
test(options)
else:
raise nimbleError(msg = "Could not find task $1 in $2" %
[options.action.command, nimbleFile],
hint = "Run `nimble --help` and/or `nimble tasks` for" &
" a list of possible commands.")
raiseNimbleError(msg = "Could not find task $1 in $2" %
[options.action.command, nimbleFile],
hint = "Run `nimble --help` and/or `nimble tasks` for" &
" a list of possible commands.")

when isMainModule:
var exitCode = QuitSuccess
Expand Down