From e0b4f05053e87b5b498c53338eed643787783b18 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Tue, 1 Dec 2020 12:12:40 -0800 Subject: nimout now consistently uses nimoutCheck (#16189) --- testament/lib/stdtest/testutils.nim | 11 +++++++++++ testament/testament.nim | 16 ++++------------ tests/casestmt/tcaseexpr1.nim | 16 ++++++++-------- tests/stdlib/ttestutils.nim | 6 ++++++ 4 files changed, 29 insertions(+), 20 deletions(-) create mode 100644 tests/stdlib/ttestutils.nim diff --git a/testament/lib/stdtest/testutils.nim b/testament/lib/stdtest/testutils.nim index 8083a63e8..34aa3b751 100644 --- a/testament/lib/stdtest/testutils.nim +++ b/testament/lib/stdtest/testutils.nim @@ -1,4 +1,5 @@ import std/private/miscdollars +import std/strutils template flakyAssert*(cond: untyped, msg = "", notifySuccess = true) = ## API to deal with flaky or failing tests. This avoids disabling entire tests @@ -23,3 +24,13 @@ template flakyAssert*(cond: untyped, msg = "", notifySuccess = true) = msg2.add " FLAKY_FAILURE " msg2.add $expr & " " & msg echo msg2 + +proc greedyOrderedSubsetLines*(lhs, rhs: string): bool = + ## returns true if each stripped line in `lhs` appears in rhs, using a greedy matching. + let rhs = rhs.strip + var currentPos = 0 + for line in lhs.strip.splitLines: + currentPos = rhs.find(line.strip, currentPos) + if currentPos < 0: + return false + return true diff --git a/testament/testament.nim b/testament/testament.nim index f2ac9c338..58b3a8040 100644 --- a/testament/testament.nim +++ b/testament/testament.nim @@ -15,6 +15,7 @@ import algorithm, times, md5, sequtils, azure, intsets from std/sugar import dup import compiler/nodejs +import lib/stdtest/testutils var useColors = true var backendLogging = true @@ -364,7 +365,7 @@ proc cmpMsgs(r: var TResults, expected, given: TSpec, test: TTest, target: TTarg checkForInlineErrors(r, expected, given, test, target) elif strip(expected.msg) notin strip(given.msg): r.addResult(test, target, expected.msg, given.msg, reMsgsDiffer) - elif expected.nimout.len > 0 and expected.nimout.normalizeMsg notin given.nimout.normalizeMsg: + elif expected.nimout.len > 0 and not greedyOrderedSubsetLines(expected.nimout, given.nimout): r.addResult(test, target, expected.nimout, given.nimout, reMsgsDiffer) elif expected.tfile == "" and extractFilename(expected.file) != extractFilename(given.file) and "internal error:" notin expected.msg: @@ -422,17 +423,8 @@ proc codegenCheck(test: TTest, target: TTarget, spec: TSpec, expectedMsg: var st echo getCurrentExceptionMsg() proc nimoutCheck(test: TTest; expectedNimout: string; given: var TSpec) = - let giv = given.nimout.strip - var currentPos = 0 - # Only check that nimout contains all expected lines in that order. - # There may be more output in nimout. It is ignored here. - for line in expectedNimout.strip.splitLines: - currentPos = giv.find(line.strip, currentPos) - if currentPos < 0: - given.err = reMsgsDiffer - break - - + if not greedyOrderedSubsetLines(expectedNimout, given.nimout): + given.err = reMsgsDiffer proc compilerOutputTests(test: TTest, target: TTarget, given: var TSpec, expected: TSpec; r: var TResults) = diff --git a/tests/casestmt/tcaseexpr1.nim b/tests/casestmt/tcaseexpr1.nim index 82af2410b..4f5bbf100 100644 --- a/tests/casestmt/tcaseexpr1.nim +++ b/tests/casestmt/tcaseexpr1.nim @@ -3,18 +3,18 @@ discard """ action: "reject" nimout: ''' tcaseexpr1.nim(33, 10) Error: not all cases are covered; missing: {C} +tcaseexpr1.nim(39, 12) Error: type mismatch: got but expected 'int literal(10)' ''' """ -#[ -# xxx make nimout comparison use nimoutCheck instead of: -elif expected.nimout.len > 0 and expected.nimout.normalizeMsg notin given.nimout.normalizeMsg: -and then use nimout: ''' -tcaseexpr1.nim(33, 10) Error: not all cases are covered2; missing: {C} -tcaseexpr1.nim(39, 12) Error: type mismatch: got but expected 'int literal(10)' -''' -]# + + + + + + + # line 20 diff --git a/tests/stdlib/ttestutils.nim b/tests/stdlib/ttestutils.nim new file mode 100644 index 000000000..1a50d311b --- /dev/null +++ b/tests/stdlib/ttestutils.nim @@ -0,0 +1,6 @@ +import stdtest/testutils + +block: # greedyOrderedSubsetLines + doAssert greedyOrderedSubsetLines("a1\na3", "a0\na1\na2\na3\na4") + doAssert not greedyOrderedSubsetLines("a3\na1", "a0\na1\na2\na3\na4") # out of order + doAssert not greedyOrderedSubsetLines("a1\na5", "a0\na1\na2\na3\na4") # a5 not in lhs -- cgit 1.4.1-2-gfad0