nimout now consistently uses nimoutCheck (#16189)

This commit is contained in:
Timothee Cour
2020-12-01 12:12:40 -08:00
committed by GitHub
parent 62eb1312a0
commit e0b4f05053
4 changed files with 29 additions and 20 deletions

View File

@@ -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

View File

@@ -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) =

View File

@@ -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 <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

View 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