Skip to content

Commit cdedb86

Browse files
authored
testament: introduce 'matrix' for testing multiple options (#13343)
1 parent 1f725f1 commit cdedb86

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

testament/specs.nim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ type
6969
maxCodeSize*: int
7070
err*: TResultEnum
7171
targets*: set[TTarget]
72+
matrix*: seq[string]
7273
nimout*: string
7374
parseErrors*: string # when the spec definition is invalid, this is not empty.
7475
unjoinable*: bool
@@ -265,6 +266,9 @@ proc parseSpec*(filename: string): TSpec =
265266
result.targets.incl(targetJS)
266267
else:
267268
result.parseErrors.addLine "cannot interpret as a target: ", e.value
269+
of "matrix":
270+
for v in e.value.split(';'):
271+
result.matrix.add(v.strip)
268272
else:
269273
result.parseErrors.addLine "invalid key for test spec: ", e.key
270274

testament/testament.nim

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Options:
4343
--targets:"c c++ js objc" run tests for specified targets (default: all)
4444
--nim:path use a particular nim executable (default: $$PATH/nim)
4545
--directory:dir Change to directory dir before reading the tests or doing anything else.
46-
--colors:on|off Turn messagescoloring on|off.
46+
--colors:on|off Turn messages coloring on|off.
4747
--backendLogging:on|off Disable or enable backend logging. By default turned on.
4848
--megatest:on|off Enable or disable megatest. Default is on.
4949
--skipFrom:file Read tests to skip from `file` - one test per line, # comments ignored
@@ -134,15 +134,14 @@ proc nimcacheDir(filename, options: string, target: TTarget): string =
134134
result = "nimcache" / (filename & '_' & hashInput.getMD5)
135135

136136
proc prepareTestArgs(cmdTemplate, filename, options, nimcache: string,
137-
target: TTarget, extraOptions=""): seq[string] =
138-
let options = options & " " & quoteShell("--nimCache:" & nimcache) & extraOptions
137+
target: TTarget, extraOptions = ""): seq[string] =
138+
let options = options & " " & quoteShell("--nimCache:" & nimcache) & " " & extraOptions
139139
result = parseCmdLine(cmdTemplate % ["target", targetToCmd[target],
140140
"options", options, "file", filename.quoteShell,
141141
"filedir", filename.getFileDir()])
142142

143143
proc callCompiler(cmdTemplate, filename, options, nimcache: string,
144-
target: TTarget,
145-
extraOptions=""): TSpec =
144+
target: TTarget, extraOptions = ""): TSpec =
146145
let c = prepareTestArgs(cmdTemplate, filename, options, nimcache, target,
147146
extraOptions)
148147
result.cmd = quoteShellCommand(c)
@@ -421,14 +420,16 @@ proc checkDisabled(r: var TResults, test: TTest): bool =
421420

422421
var count = 0
423422

424-
proc testSpecHelper(r: var TResults, test: TTest, expected: TSpec, target: TTarget, nimcache: string) =
423+
proc testSpecHelper(r: var TResults, test: TTest, expected: TSpec,
424+
target: TTarget, nimcache: string, extraOptions = "") =
425425
case expected.action
426426
of actionCompile:
427427
var given = callCompiler(expected.getCmd, test.name, test.options, nimcache, target,
428428
extraOptions = " --stdout --hint[Path]:off --hint[Processing]:off")
429429
compilerOutputTests(test, target, given, expected, r)
430430
of actionRun:
431-
var given = callCompiler(expected.getCmd, test.name, test.options, nimcache, target)
431+
var given = callCompiler(expected.getCmd, test.name, test.options,
432+
nimcache, target, extraOptions)
432433
if given.err != reSuccess:
433434
r.addResult(test, target, "", "$ " & given.cmd & "\n" & given.nimout, given.err)
434435
else:
@@ -484,6 +485,18 @@ proc testSpecHelper(r: var TResults, test: TTest, expected: TSpec, target: TTarg
484485
nimcache, target)
485486
cmpMsgs(r, expected, given, test, target)
486487

488+
proc targetHelper(r: var TResults, test: TTest, expected: TSpec, extraOptions = "") =
489+
for target in expected.targets:
490+
inc(r.total)
491+
if target notin gTargets:
492+
r.addResult(test, target, "", "", reDisabled)
493+
inc(r.skipped)
494+
elif simulate:
495+
inc count
496+
echo "testSpec count: ", count, " expected: ", expected
497+
else:
498+
let nimcache = nimcacheDir(test.name, test.options, target)
499+
testSpecHelper(r, test, expected, target, nimcache, extraOptions)
487500

488501
proc testSpec(r: var TResults, test: TTest, targets: set[TTarget] = {}) =
489502
var expected = test.spec
@@ -498,17 +511,11 @@ proc testSpec(r: var TResults, test: TTest, targets: set[TTarget] = {}) =
498511
# still no target specified at all
499512
if expected.targets == {}:
500513
expected.targets = {getTestSpecTarget()}
501-
for target in expected.targets:
502-
inc(r.total)
503-
if target notin gTargets:
504-
r.addResult(test, target, "", "", reDisabled)
505-
inc(r.skipped)
506-
elif simulate:
507-
inc count
508-
echo "testSpec count: ", count, " expected: ", expected
509-
else:
510-
let nimcache = nimcacheDir(test.name, test.options, target)
511-
testSpecHelper(r, test, expected, target, nimcache)
514+
if test.spec.matrix.len > 0:
515+
for m in test.spec.matrix:
516+
targetHelper(r, test, expected, m)
517+
else:
518+
targetHelper(r, test, expected)
512519

513520
proc testSpecWithNimcache(r: var TResults, test: TTest; nimcache: string) =
514521
if not checkDisabled(r, test): return

tests/misc/tdangerisrelease.nim

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
discard """
2-
cmd: "nim c -d:danger -r $file"
2+
cmd: "nim $target $options -r $file"
3+
targets: "c cpp"
4+
matrix: "-d:danger; -d:release"
35
output: '''
46
a
57
b

0 commit comments

Comments
 (0)