From 5b94a1b70cf0666cc6b21a3c504b98e6146ea818 Mon Sep 17 00:00:00 2001 From: Julian Fondren Date: Sat, 4 May 2019 18:58:12 -0500 Subject: [PATCH] test -c,--continue option to continue tests on error --- src/nimble.nim | 19 ++++++++++++++++--- src/nimblepkg/options.nim | 5 +++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/nimble.nim b/src/nimble.nim index e0b10f3..f1034df 100644 --- a/src/nimble.nim +++ b/src/nimble.nim @@ -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. diff --git a/src/nimblepkg/options.nim b/src/nimblepkg/options.nim index 749a4ed..70924bd 100644 --- a/src/nimblepkg/options.nim +++ b/src/nimblepkg/options.nim @@ -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