Skip to content

Commit 809a8c6

Browse files
timotheecourPMunch
authored andcommitted
testament: add nimoutFull: bool spec (nim-lang#17867)
* testament: add `nimoutFull: bool` spec * PRTEMP * works * cleanup * add test for nim-lang#12741 * PRTEMP failing test * remove unrelated changes * changelog
1 parent e0e785c commit 809a8c6

File tree

7 files changed

+43
-9
lines changed

7 files changed

+43
-9
lines changed

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,3 +399,6 @@
399399

400400
- `fusion` is now un-bundled from nim, `./koch fusion` will
401401
install it via nimble at a fixed hash.
402+
403+
- testament: added `nimoutFull: bool` spec to compare full output of compiler
404+
instead of a subset.

testament/categories.nim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,9 @@ proc isJoinableSpec(spec: TSpec): bool =
576576
spec.exitCode == 0 and
577577
spec.input.len == 0 and
578578
spec.nimout.len == 0 and
579+
spec.nimoutFull == false and
580+
# so that tests can have `nimoutFull: true` with `nimout.len == 0` with
581+
# the meaning that they expect empty output.
579582
spec.matrix.len == 0 and
580583
spec.outputCheck != ocSubstr and
581584
spec.ccodeCheck.len == 0 and

testament/specs.nim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ type
8888
targets*: set[TTarget]
8989
matrix*: seq[string]
9090
nimout*: string
91+
nimoutFull*: bool # whether nimout is all compiler output or a subset
9192
parseErrors*: string # when the spec definition is invalid, this is not empty.
9293
unjoinable*: bool
9394
unbatchable*: bool
@@ -297,6 +298,8 @@ proc parseSpec*(filename: string): TSpec =
297298
result.action = actionReject
298299
of "nimout":
299300
result.nimout = e.value
301+
of "nimoutfull":
302+
result.nimoutFull = parseCfgBool(e.value)
300303
of "batchable":
301304
result.unbatchable = not parseCfgBool(e.value)
302305
of "joinable":

testament/testament.nim

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -371,12 +371,20 @@ proc checkForInlineErrors(r: var TResults, expected, given: TSpec, test: TTest,
371371
r.addResult(test, target, "", given.msg, reSuccess)
372372
inc(r.passed)
373373

374+
proc nimoutCheck(expected, given: TSpec): bool =
375+
result = true
376+
if expected.nimoutFull:
377+
if expected.nimout != given.nimout:
378+
result = false
379+
elif expected.nimout.len > 0 and not greedyOrderedSubsetLines(expected.nimout, given.nimout):
380+
result = false
381+
374382
proc cmpMsgs(r: var TResults, expected, given: TSpec, test: TTest, target: TTarget) =
375383
if expected.inlineErrors.len > 0:
376384
checkForInlineErrors(r, expected, given, test, target)
377385
elif strip(expected.msg) notin strip(given.msg):
378386
r.addResult(test, target, expected.msg, given.msg, reMsgsDiffer)
379-
elif expected.nimout.len > 0 and not greedyOrderedSubsetLines(expected.nimout, given.nimout):
387+
elif not nimoutCheck(expected, given):
380388
r.addResult(test, target, expected.nimout, given.nimout, reMsgsDiffer)
381389
elif extractFilename(expected.file) != extractFilename(given.file) and
382390
"internal error:" notin expected.msg:
@@ -424,10 +432,6 @@ proc codegenCheck(test: TTest, target: TTarget, spec: TSpec, expectedMsg: var st
424432
given.err = reCodeNotFound
425433
echo getCurrentExceptionMsg()
426434

427-
proc nimoutCheck(test: TTest; expectedNimout: string; given: var TSpec) =
428-
if not greedyOrderedSubsetLines(expectedNimout, given.nimout):
429-
given.err = reMsgsDiffer
430-
431435
proc compilerOutputTests(test: TTest, target: TTarget, given: var TSpec,
432436
expected: TSpec; r: var TResults) =
433437
var expectedmsg: string = ""
@@ -436,10 +440,10 @@ proc compilerOutputTests(test: TTest, target: TTarget, given: var TSpec,
436440
if expected.needsCodegenCheck:
437441
codegenCheck(test, target, expected, expectedmsg, given)
438442
givenmsg = given.msg
439-
if expected.nimout.len > 0:
443+
if not nimoutCheck(expected, given):
444+
given.err = reMsgsDiffer
440445
expectedmsg = expected.nimout
441446
givenmsg = given.nimout.strip
442-
nimoutCheck(test, expectedmsg, given)
443447
else:
444448
givenmsg = "$ " & given.cmd & '\n' & given.nimout
445449
if given.err == reSuccess: inc(r.passed)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
discard """
2+
targets: "c"
3+
nimout: '''
4+
msg1
5+
msg2
6+
'''
7+
action: compile
8+
nimoutFull: true
9+
"""
10+
11+
# should fail because `msg3` is not in nimout and `nimoutFill: true` was given
12+
static:
13+
echo "msg1"
14+
echo "msg2"
15+
echo "msg3"

tests/config.nims

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ switch("path", "$lib/../testament/lib")
66
## prevent common user config settings to interfere with testament expectations
77
## Indifidual tests can override this if needed to test for these options.
88
switch("colors", "off")
9-
switch("filenames", "legacyRelProj")
9+
1010
switch("excessiveStackTrace", "off")
11-
switch("spellSuggest", "0")
11+
12+
when (NimMajor, NimMinor, NimPatch) >= (1,5,1):
13+
# to make it easier to test against older nim versions, (best effort only)
14+
switch("filenames", "legacyRelProj")
15+
switch("spellSuggest", "0")
1216

1317
# for std/unittest
1418
switch("define", "nimUnittestOutputLevel:PRINT_FAILURES")

tests/testament/tshould_not_work.nim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Failure: reCodegenFailure
2121
max allowed size: 1
2222
FAIL: tests/shouldfail/tnimout.nim c
2323
Failure: reMsgsDiffer
24+
FAIL: tests/shouldfail/tnimoutfull.nim c
25+
Failure: reMsgsDiffer
2426
FAIL: tests/shouldfail/toutput.nim c
2527
Failure: reOutputsDiffer
2628
FAIL: tests/shouldfail/toutputsub.nim c

0 commit comments

Comments
 (0)