Merge pull request #647 from jrfondren/continue-tests-on-error

Option to continue tests on failure
This commit is contained in:
Dominik Picheta 2019-05-06 16:28:18 +01:00 committed by GitHub
commit f17eaef795
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 3 deletions

View file

@ -992,7 +992,9 @@ proc develop(options: Options) =
proc test(options: Options) =
## Executes all tests starting with 't' in the ``tests`` directory.
## Subdirectories are not walked.
var files = toSeq(walkDir(getCurrentDir() / "tests"))
var
files = toSeq(walkDir(getCurrentDir() / "tests"))
tests, failures: int
if files.len < 1:
display("Warning:", "No tests found!", Warning, HighPriority)
@ -1014,7 +1016,14 @@ proc test(options: Options) =
binFileName = file.path.changeFileExt(ExeExt)
existsBefore = existsFile(binFileName)
execBackend(optsCopy)
if options.continueTestsOnFailure:
inc tests
try:
execBackend(optsCopy)
except NimbleError:
inc failures
else:
execBackend(optsCopy)
let
existsAfter = existsFile(binFileName)
@ -1022,7 +1031,11 @@ proc test(options: Options) =
if canRemove:
removeFile(binFileName)
display("Success:", "All tests passed", Success, HighPriority)
if failures == 0:
display("Success:", "All tests passed", Success, HighPriority)
else:
let error = "Only " & $(tests - failures) & "/" & $tests & " tests passed"
display("Error:", error, Error, HighPriority)
proc check(options: Options) =
## Validates a package a in the current working directory.

View file

@ -23,6 +23,7 @@ type
showVersion*: bool
noColor*: bool
disableValidation*: bool
continueTestsOnFailure*: bool
## Whether packages' repos should always be downloaded with their history.
forceFullClone*: bool
@ -77,6 +78,7 @@ Commands:
c, cc, js [opts, ...] f.nim Builds a file inside a package. Passes options
to the Nim compiler.
test Compiles and executes tests
[-c, --continue] Don't stop execution on a failed test.
doc, doc2 [opts, ...] f.nim Builds documentation for a file inside a
package. Passes options to the Nim compiler.
refresh [url] Refreshes the package list. A package list URL
@ -316,6 +318,9 @@ proc parseFlag*(flag, val: string, result: var Options, kind = cmdLongOption) =
else:
result.action.compileOptions.add(prefix & flag & ":" & val)
of actionCustom:
if result.action.command.normalize == "test":
if f == "continue" or f == "c":
result.continueTestsOnFailure = true
result.action.flags[flag] = val
else:
wasFlagHandled = false