testament: add nimoutFull: bool spec (#17867)

* testament: add `nimoutFull: bool` spec
* PRTEMP
* works
* cleanup
* add test for #12741
* PRTEMP failing test
* remove unrelated changes
* changelog
This commit is contained in:
Timothee Cour 2021-04-27 02:11:28 -07:00 • committed by GitHub
commit a236002e54
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 43 additions and 9 deletions

View file

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

View file

@ -576,6 +576,9 @@ proc isJoinableSpec(spec: TSpec): bool =
spec.exitCode == 0 and spec.exitCode == 0 and
spec.input.len == 0 and spec.input.len == 0 and
spec.nimout.len == 0 and spec.nimout.len == 0 and
spec.nimoutFull == false and
# so that tests can have `nimoutFull: true` with `nimout.len == 0` with
# the meaning that they expect empty output.
spec.matrix.len == 0 and spec.matrix.len == 0 and
spec.outputCheck != ocSubstr and spec.outputCheck != ocSubstr and
spec.ccodeCheck.len == 0 and spec.ccodeCheck.len == 0 and

View file

@ -88,6 +88,7 @@ type
targets*: set[TTarget] targets*: set[TTarget]
matrix*: seq[string] matrix*: seq[string]
nimout*: string nimout*: string
nimoutFull*: bool # whether nimout is all compiler output or a subset
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
unbatchable*: bool unbatchable*: bool
@ -297,6 +298,8 @@ proc parseSpec*(filename: string): TSpec =
result.action = actionReject result.action = actionReject
of "nimout": of "nimout":
result.nimout = e.value result.nimout = e.value
of "nimoutfull":
result.nimoutFull = parseCfgBool(e.value)
of "batchable": of "batchable":
result.unbatchable = not parseCfgBool(e.value) result.unbatchable = not parseCfgBool(e.value)
of "joinable": of "joinable":

View file

@ -371,12 +371,20 @@ proc checkForInlineErrors(r: var TResults, expected, given: TSpec, test: TTest,
r.addResult(test, target, "", given.msg, reSuccess) r.addResult(test, target, "", given.msg, reSuccess)
inc(r.passed) inc(r.passed)
proc nimoutCheck(expected, given: TSpec): bool =
result = true
if expected.nimoutFull:
if expected.nimout != given.nimout:
result = false
elif expected.nimout.len > 0 and not greedyOrderedSubsetLines(expected.nimout, given.nimout):
result = false
proc cmpMsgs(r: var TResults, expected, given: TSpec, test: TTest, target: TTarget) = proc cmpMsgs(r: var TResults, expected, given: TSpec, test: TTest, target: TTarget) =
if expected.inlineErrors.len > 0: if expected.inlineErrors.len > 0:
checkForInlineErrors(r, expected, given, test, target) checkForInlineErrors(r, expected, given, test, target)
elif strip(expected.msg) notin strip(given.msg): elif strip(expected.msg) notin strip(given.msg):
r.addResult(test, target, expected.msg, given.msg, reMsgsDiffer) r.addResult(test, target, expected.msg, given.msg, reMsgsDiffer)
elif expected.nimout.len > 0 and not greedyOrderedSubsetLines(expected.nimout, given.nimout): elif not nimoutCheck(expected, given):
r.addResult(test, target, expected.nimout, given.nimout, reMsgsDiffer) r.addResult(test, target, expected.nimout, given.nimout, reMsgsDiffer)
elif extractFilename(expected.file) != extractFilename(given.file) and elif extractFilename(expected.file) != extractFilename(given.file) and
"internal error:" notin expected.msg: "internal error:" notin expected.msg:
@ -424,10 +432,6 @@ proc codegenCheck(test: TTest, target: TTarget, spec: TSpec, expectedMsg: var st
given.err = reCodeNotFound given.err = reCodeNotFound
echo getCurrentExceptionMsg() echo getCurrentExceptionMsg()
proc nimoutCheck(test: TTest; expectedNimout: string; given: var TSpec) =
if not greedyOrderedSubsetLines(expectedNimout, given.nimout):
given.err = reMsgsDiffer
proc compilerOutputTests(test: TTest, target: TTarget, given: var TSpec, proc compilerOutputTests(test: TTest, target: TTarget, given: var TSpec,
expected: TSpec; r: var TResults) = expected: TSpec; r: var TResults) =
var expectedmsg: string = "" var expectedmsg: string = ""
@ -436,10 +440,10 @@ proc compilerOutputTests(test: TTest, target: TTarget, given: var TSpec,
if expected.needsCodegenCheck: if expected.needsCodegenCheck:
codegenCheck(test, target, expected, expectedmsg, given) codegenCheck(test, target, expected, expectedmsg, given)
givenmsg = given.msg givenmsg = given.msg
if expected.nimout.len > 0: if not nimoutCheck(expected, given):
given.err = reMsgsDiffer
expectedmsg = expected.nimout expectedmsg = expected.nimout
givenmsg = given.nimout.strip givenmsg = given.nimout.strip
nimoutCheck(test, expectedmsg, given)
else: else:
givenmsg = "$ " & given.cmd & '\n' & given.nimout givenmsg = "$ " & given.cmd & '\n' & given.nimout
if given.err == reSuccess: inc(r.passed) if given.err == reSuccess: inc(r.passed)

View file

@ -0,0 +1,15 @@
discard """
targets: "c"
nimout: '''
msg1
msg2
'''
action: compile
nimoutFull: true
"""
# should fail because `msg3` is not in nimout and `nimoutFill: true` was given
static:
echo "msg1"
echo "msg2"
echo "msg3"

View file

@ -6,8 +6,12 @@ switch("path", "$lib/../testament/lib")
## prevent common user config settings to interfere with testament expectations ## prevent common user config settings to interfere with testament expectations
## Indifidual tests can override this if needed to test for these options. ## Indifidual tests can override this if needed to test for these options.
switch("colors", "off") switch("colors", "off")
switch("filenames", "legacyRelProj")
switch("excessiveStackTrace", "off") switch("excessiveStackTrace", "off")
when (NimMajor, NimMinor, NimPatch) >= (1,5,1):
# to make it easier to test against older nim versions, (best effort only)
switch("filenames", "legacyRelProj")
switch("spellSuggest", "0") switch("spellSuggest", "0")
# for std/unittest # for std/unittest

View file

@ -21,6 +21,8 @@ Failure: reCodegenFailure
max allowed size: 1 max allowed size: 1
FAIL: tests/shouldfail/tnimout.nim c FAIL: tests/shouldfail/tnimout.nim c
Failure: reMsgsDiffer Failure: reMsgsDiffer
FAIL: tests/shouldfail/tnimoutfull.nim c
Failure: reMsgsDiffer
FAIL: tests/shouldfail/toutput.nim c FAIL: tests/shouldfail/toutput.nim c
Failure: reOutputsDiffer Failure: reOutputsDiffer
FAIL: tests/shouldfail/toutputsub.nim c FAIL: tests/shouldfail/toutputsub.nim c