testament: introduce 'matrix' for testing multiple options (#13343)

This commit is contained in:
Miran 2020-02-07 16:45:49 +01:00 • committed by GitHub
commit cdedb86348
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 19 deletions

View file

@ -69,6 +69,7 @@ type
maxCodeSize*: int maxCodeSize*: int
err*: TResultEnum err*: TResultEnum
targets*: set[TTarget] targets*: set[TTarget]
matrix*: seq[string]
nimout*: string nimout*: string
parseErrors*: string # when the spec definition is invalid, this is not empty. parseErrors*: string # when the spec definition is invalid, this is not empty.
unjoinable*: bool unjoinable*: bool
@ -265,6 +266,9 @@ proc parseSpec*(filename: string): TSpec =
result.targets.incl(targetJS) result.targets.incl(targetJS)
else: else:
result.parseErrors.addLine "cannot interpret as a target: ", e.value result.parseErrors.addLine "cannot interpret as a target: ", e.value
of "matrix":
for v in e.value.split(';'):
result.matrix.add(v.strip)
else: else:
result.parseErrors.addLine "invalid key for test spec: ", e.key result.parseErrors.addLine "invalid key for test spec: ", e.key

View file

@ -135,14 +135,13 @@ proc nimcacheDir(filename, options: string, target: TTarget): string =
proc prepareTestArgs(cmdTemplate, filename, options, nimcache: string, proc prepareTestArgs(cmdTemplate, filename, options, nimcache: string,
target: TTarget, extraOptions = ""): seq[string] = target: TTarget, extraOptions = ""): seq[string] =
let options = options & " " & quoteShell("--nimCache:" & nimcache) & extraOptions let options = options & " " & quoteShell("--nimCache:" & nimcache) & " " & extraOptions
result = parseCmdLine(cmdTemplate % ["target", targetToCmd[target], result = parseCmdLine(cmdTemplate % ["target", targetToCmd[target],
"options", options, "file", filename.quoteShell, "options", options, "file", filename.quoteShell,
"filedir", filename.getFileDir()]) "filedir", filename.getFileDir()])
proc callCompiler(cmdTemplate, filename, options, nimcache: string, proc callCompiler(cmdTemplate, filename, options, nimcache: string,
target: TTarget, target: TTarget, extraOptions = ""): TSpec =
extraOptions=""): TSpec =
let c = prepareTestArgs(cmdTemplate, filename, options, nimcache, target, let c = prepareTestArgs(cmdTemplate, filename, options, nimcache, target,
extraOptions) extraOptions)
result.cmd = quoteShellCommand(c) result.cmd = quoteShellCommand(c)
@ -421,14 +420,16 @@ proc checkDisabled(r: var TResults, test: TTest): bool =
var count = 0 var count = 0
proc testSpecHelper(r: var TResults, test: TTest, expected: TSpec, target: TTarget, nimcache: string) = proc testSpecHelper(r: var TResults, test: TTest, expected: TSpec,
target: TTarget, nimcache: string, extraOptions = "") =
case expected.action case expected.action
of actionCompile: of actionCompile:
var given = callCompiler(expected.getCmd, test.name, test.options, nimcache, target, var given = callCompiler(expected.getCmd, test.name, test.options, nimcache, target,
extraOptions = " --stdout --hint[Path]:off --hint[Processing]:off") extraOptions = " --stdout --hint[Path]:off --hint[Processing]:off")
compilerOutputTests(test, target, given, expected, r) compilerOutputTests(test, target, given, expected, r)
of actionRun: of actionRun:
var given = callCompiler(expected.getCmd, test.name, test.options, nimcache, target) var given = callCompiler(expected.getCmd, test.name, test.options,
nimcache, target, extraOptions)
if given.err != reSuccess: if given.err != reSuccess:
r.addResult(test, target, "", "$ " & given.cmd & "\n" & given.nimout, given.err) r.addResult(test, target, "", "$ " & given.cmd & "\n" & given.nimout, given.err)
else: else:
@ -484,6 +485,18 @@ proc testSpecHelper(r: var TResults, test: TTest, expected: TSpec, target: TTarg
nimcache, target) nimcache, target)
cmpMsgs(r, expected, given, test, target) cmpMsgs(r, expected, given, test, target)
proc targetHelper(r: var TResults, test: TTest, expected: TSpec, extraOptions = "") =
for target in expected.targets:
inc(r.total)
if target notin gTargets:
r.addResult(test, target, "", "", reDisabled)
inc(r.skipped)
elif simulate:
inc count
echo "testSpec count: ", count, " expected: ", expected
else:
let nimcache = nimcacheDir(test.name, test.options, target)
testSpecHelper(r, test, expected, target, nimcache, extraOptions)
proc testSpec(r: var TResults, test: TTest, targets: set[TTarget] = {}) = proc testSpec(r: var TResults, test: TTest, targets: set[TTarget] = {}) =
var expected = test.spec var expected = test.spec
@ -498,17 +511,11 @@ proc testSpec(r: var TResults, test: TTest, targets: set[TTarget] = {}) =
# still no target specified at all # still no target specified at all
if expected.targets == {}: if expected.targets == {}:
expected.targets = {getTestSpecTarget()} expected.targets = {getTestSpecTarget()}
for target in expected.targets: if test.spec.matrix.len > 0:
inc(r.total) for m in test.spec.matrix:
if target notin gTargets: targetHelper(r, test, expected, m)
r.addResult(test, target, "", "", reDisabled)
inc(r.skipped)
elif simulate:
inc count
echo "testSpec count: ", count, " expected: ", expected
else: else:
let nimcache = nimcacheDir(test.name, test.options, target) targetHelper(r, test, expected)
testSpecHelper(r, test, expected, target, nimcache)
proc testSpecWithNimcache(r: var TResults, test: TTest; nimcache: string) = proc testSpecWithNimcache(r: var TResults, test: TTest; nimcache: string) =
if not checkDisabled(r, test): return if not checkDisabled(r, test): return

View file

@ -1,5 +1,7 @@
discard """ discard """
cmd: "nim c -d:danger -r $file" cmd: "nim $target $options -r $file"
targets: "c cpp"
matrix: "-d:danger; -d:release"
output: ''' output: '''
a a
b b