summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2020-12-01 12:12:40 -0800
committerGitHub <noreply@github.com>2020-12-01 21:12:40 +0100
commite0b4f05053e87b5b498c53338eed643787783b18 (patch)
tree4a7b9b5f1a43436a6686b8e4ab4e2c8b2ba66d70
parent62eb1312a099aeae0115beb038ed8449ccd095a7 (diff)
downloadNim-e0b4f05053e87b5b498c53338eed643787783b18.tar.gz
nimout now consistently uses nimoutCheck (#16189)
-rw-r--r--testament/lib/stdtest/testutils.nim11
-rw-r--r--testament/testament.nim16
-rw-r--r--tests/casestmt/tcaseexpr1.nim16
-rw-r--r--tests/stdlib/ttestutils.nim6
4 files changed, 29 insertions, 20 deletions
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 <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
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