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
Show file tree
Hide file tree
Changes from all commits
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
25 changes: 7 additions & 18 deletions src/nimble.nim
Original file line number Diff line number Diff line change
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,24 +1407,23 @@ 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()
if ext == ".nim" and name[0] == 't' and file.kind in {pcFile, pcLinkToFile}:
let (_, name, ext) = file.splitFile()
if ext == ".nim" and name[0] == 't':
var optsCopy = options
optsCopy.action = Action(typ: actionCompile)
optsCopy.action.file = file.path
optsCopy.action.file = file
optsCopy.action.additionalArguments = options.action.arguments
optsCopy.action.backend = pkgInfo.backend
optsCopy.getCompilationFlags() = options.getCompilationFlags()
# 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
7 changes: 0 additions & 7 deletions tests/ttestcommand.nim
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@ suite "test command":
check outp.processOutput.inLines("overriden")
check outp.processOutput.inLines("true")

test "certain files are ignored":
cd "testCommand/testsIgnore":
let (outp, exitCode) = execNimble("test")
check exitCode == QuitSuccess
check(not outp.processOutput.inLines("Should be ignored"))
check outp.processOutput.inLines("First test")

test "CWD is root of package":
cd "testCommand/testsCWD":
let (outp, exitCode) = execNimble("test")
Expand Down