nimout now consistently uses nimoutCheck (#16189)
This commit is contained in:
parent
62eb1312a0
commit
e0b4f05053
4 changed files with 29 additions and 20 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
import std/private/miscdollars
|
import std/private/miscdollars
|
||||||
|
import std/strutils
|
||||||
|
|
||||||
template flakyAssert*(cond: untyped, msg = "", notifySuccess = true) =
|
template flakyAssert*(cond: untyped, msg = "", notifySuccess = true) =
|
||||||
## API to deal with flaky or failing tests. This avoids disabling entire tests
|
## 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 " FLAKY_FAILURE "
|
||||||
msg2.add $expr & " " & msg
|
msg2.add $expr & " " & msg
|
||||||
echo msg2
|
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
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import
|
||||||
algorithm, times, md5, sequtils, azure, intsets
|
algorithm, times, md5, sequtils, azure, intsets
|
||||||
from std/sugar import dup
|
from std/sugar import dup
|
||||||
import compiler/nodejs
|
import compiler/nodejs
|
||||||
|
import lib/stdtest/testutils
|
||||||
|
|
||||||
var useColors = true
|
var useColors = true
|
||||||
var backendLogging = 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)
|
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 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)
|
r.addResult(test, target, expected.nimout, given.nimout, reMsgsDiffer)
|
||||||
elif expected.tfile == "" and extractFilename(expected.file) != extractFilename(given.file) and
|
elif expected.tfile == "" and extractFilename(expected.file) != extractFilename(given.file) and
|
||||||
"internal error:" notin expected.msg:
|
"internal error:" notin expected.msg:
|
||||||
|
|
@ -422,17 +423,8 @@ proc codegenCheck(test: TTest, target: TTarget, spec: TSpec, expectedMsg: var st
|
||||||
echo getCurrentExceptionMsg()
|
echo getCurrentExceptionMsg()
|
||||||
|
|
||||||
proc nimoutCheck(test: TTest; expectedNimout: string; given: var TSpec) =
|
proc nimoutCheck(test: TTest; expectedNimout: string; given: var TSpec) =
|
||||||
let giv = given.nimout.strip
|
if not greedyOrderedSubsetLines(expectedNimout, given.nimout):
|
||||||
var currentPos = 0
|
given.err = reMsgsDiffer
|
||||||
# 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
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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) =
|
||||||
|
|
|
||||||
|
|
@ -3,18 +3,18 @@ discard """
|
||||||
action: "reject"
|
action: "reject"
|
||||||
nimout: '''
|
nimout: '''
|
||||||
tcaseexpr1.nim(33, 10) Error: not all cases are covered; missing: {C}
|
tcaseexpr1.nim(33, 10) Error: not all cases are covered; missing: {C}
|
||||||
|
tcaseexpr1.nim(39, 12) Error: type mismatch: got <string> 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 <string> but expected 'int literal(10)'
|
|
||||||
'''
|
|
||||||
]#
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# line 20
|
# line 20
|
||||||
|
|
|
||||||
6
tests/stdlib/ttestutils.nim
Normal file
6
tests/stdlib/ttestutils.nim
Normal file
|
|
@ -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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue