From 7b47542df95b0529414f54fd9465115198a0fb22 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Fri, 27 Nov 2020 17:23:37 -0800 Subject: [PATCH] fix #14242 `testament r tests/js/foo` now works; testament now honors --targets --- testament/categories.nim | 14 +++++++------- testament/specs.nim | 8 ++++---- testament/testament.nim | 14 +++++++++----- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/testament/categories.nim b/testament/categories.nim index 0d19842ec801e..75d4d6aae050e 100644 --- a/testament/categories.nim +++ b/testament/categories.nim @@ -563,13 +563,13 @@ proc `&.?`(a, b: string): string = # candidate for the stdlib? result = if b.startsWith(a): b else: a & b -proc processSingleTest(r: var TResults, cat: Category, options, test: string) = - let test = testsDir &.? cat.string / test - let target = if cat.string.normalize == "js": targetJS else: targetC - if fileExists(test): - testSpec r, makeTest(test, options, cat), {target} - else: - doAssert false, test & " test does not exist" +proc processSingleTest(r: var TResults, cat: Category, options, test: string, targets: typeof(gTargets), targetsSet: bool) = + var targets = targets + if not targetsSet: + let target = if cat.string.normalize == "js": targetJS else: targetC + targets = {target} + doAssert fileExists(test), test & " test does not exist" + testSpec r, makeTest(test, options, cat), targets proc isJoinableSpec(spec: TSpec): bool = result = not spec.sortoutput and diff --git a/testament/specs.nim b/testament/specs.nim index eaae598bbcc69..eccbd60b1b112 100644 --- a/testament/specs.nim +++ b/testament/specs.nim @@ -57,10 +57,10 @@ type reInvalidSpec # test had problems to parse the spec TTarget* = enum - targetC = "C" - targetCpp = "C++" - targetObjC = "ObjC" - targetJS = "JS" + targetC = "c" + targetCpp = "cpp" + targetObjC = "objc" + targetJS = "js" InlineError* = object kind*: string diff --git a/testament/testament.nim b/testament/testament.nim index 2912b03abb76e..51e3abc7f3b8a 100644 --- a/testament/testament.nim +++ b/testament/testament.nim @@ -81,6 +81,7 @@ let pegOfInterest = pegLineError / pegOtherError var gTargets = {low(TTarget)..high(TTarget)} +var targetsSet = false proc isSuccess(input: string): bool = # not clear how to do the equivalent of pkg/regex's: re"FOO(.*?)BAR" in pegs @@ -685,6 +686,7 @@ proc main() = of "targets": targetsStr = p.val.string gTargets = parseTargets(targetsStr) + targetsSet = true of "nim": compilerPrefix = addFileExt(p.val.string, ExeExt) of "directory": @@ -794,14 +796,16 @@ proc main() = p.next processPattern(r, pattern, p.cmdLineRest.string, simulate) of "r", "run": + # "/pathto/tests/stdlib/nre/captures.nim" -> "stdlib" + "tests/stdlib/nre/captures.nim" var subPath = p.key.string - if subPath.isAbsolute: subPath = subPath.relativePath(getCurrentDir()) + let nimRoot = currentSourcePath / "../.." + # makes sure points to this regardless of cwd or which nim is used to compile this. + doAssert existsDir(nimRoot/testsDir) # sanity check + if subPath.isAbsolute: subPath = subPath.relativePath(nimRoot) # at least one directory is required in the path, to use as a category name - let pathParts = split(subPath, {DirSep, AltSep}) - # "stdlib/nre/captures.nim" -> "stdlib" + "nre/captures.nim" + let pathParts = subPath.relativePath(testsDir).split({DirSep, AltSep}) let cat = Category(pathParts[0]) - subPath = joinPath(pathParts[1..^1]) - processSingleTest(r, cat, p.cmdLineRest.string, subPath) + processSingleTest(r, cat, p.cmdLineRest.string, subPath, gTargets, targetsSet) of "html": generateHtml(resultsFile, optFailing) else: