summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAman Gupta <aman@tmm1.net>2015-10-06 15:47:07 -0700
committerAman Gupta <aman@tmm1.net>2015-10-06 15:47:07 -0700
commit2240fd3f3fb32fc4b1c8c7815d6d59982df44406 (patch)
treea4404515948e6430eebff3159c657ba0eed388b7
parenteea8d604d07aae569843ebccc5bd7791cff40567 (diff)
downloadNim-2240fd3f3fb32fc4b1c8c7815d6d59982df44406.tar.gz
add tfile/tline assertions for template expansion file/line
-rw-r--r--tests/enum/tenummix.nim4
-rw-r--r--tests/misc/tnot.nim7
-rw-r--r--tests/testament/specs.nim5
-rw-r--r--tests/testament/tester.nim23
4 files changed, 31 insertions, 8 deletions
diff --git a/tests/enum/tenummix.nim b/tests/enum/tenummix.nim
index 4352cdd81..c7db4e056 100644
--- a/tests/enum/tenummix.nim
+++ b/tests/enum/tenummix.nim
@@ -1,6 +1,6 @@
 discard """
-  file: "tenummix.nim"
-  line: 11
+  tfile: "tenummix.nim"
+  tline: 11
   errormsg: "type mismatch"
 """
 
diff --git a/tests/misc/tnot.nim b/tests/misc/tnot.nim
index 60d23c035..8c75c6bc0 100644
--- a/tests/misc/tnot.nim
+++ b/tests/misc/tnot.nim
@@ -1,6 +1,6 @@
 discard """
-  file: "tnot.nim"
-  line: 14
+  tfile: "tnot.nim"
+  tline: 14
   errormsg: "type mismatch"
 """
 # BUG: following compiles, but should not:
@@ -17,6 +17,3 @@ proc main =
         echo "No"
 
 main()
-
-
-
diff --git a/tests/testament/specs.nim b/tests/testament/specs.nim
index 99640f22c..dcca8a66e 100644
--- a/tests/testament/specs.nim
+++ b/tests/testament/specs.nim
@@ -44,6 +44,8 @@ type
     file*, cmd*: string
     outp*: string
     line*, column*: int
+    tfile*: string
+    tline*, tcolumn*: int
     exitCode*: int
     msg*: string
     ccodeCheck*: string
@@ -116,6 +118,9 @@ proc parseSpec*(filename: string): TSpec =
     of "file": result.file = e.value
     of "line": discard parseInt(e.value, result.line)
     of "column": discard parseInt(e.value, result.column)
+    of "tfile": result.tfile = e.value
+    of "tline": discard parseInt(e.value, result.tline)
+    of "tcolumn": discard parseInt(e.value, result.tcolumn)
     of "output":
       result.action = actionRun
       result.outp = e.value
diff --git a/tests/testament/tester.nim b/tests/testament/tester.nim
index 814e342ca..636093a7f 100644
--- a/tests/testament/tester.nim
+++ b/tests/testament/tester.nim
@@ -53,6 +53,8 @@ type
 let
   pegLineError =
     peg"{[^(]*} '(' {\d+} ', ' {\d+} ') ' ('Error') ':' \s* {.*}"
+  pegLineTemplate =
+    peg"{[^(]*} '(' {\d+} ', ' {\d+} ') ' 'template/generic instantiation from here'.*"
   pegOtherError = peg"'Error:' \s* {.*}"
   pegSuccess = peg"'Hint: operation successful'.*"
   pegOfInterest = pegLineError / pegOtherError
@@ -66,6 +68,7 @@ proc callCompiler(cmdTemplate, filename, options: string,
   let outp = p.outputStream
   var suc = ""
   var err = ""
+  var tmpl = ""
   var x = newStringOfCap(120)
   result.nimout = ""
   while outp.readLine(x.TaintedString) or running(p):
@@ -73,6 +76,9 @@ proc callCompiler(cmdTemplate, filename, options: string,
     if x =~ pegOfInterest:
       # `err` should contain the last error/warning message
       err = x
+    elif x =~ pegLineTemplate and err == "":
+      # `tmpl` contains the last template expansion before the error
+      tmpl = x
     elif x =~ pegSuccess:
       suc = x
   close(p)
@@ -81,6 +87,13 @@ proc callCompiler(cmdTemplate, filename, options: string,
   result.outp = ""
   result.line = 0
   result.column = 0
+  result.tfile = ""
+  result.tline = 0
+  result.tcolumn = 0
+  if tmpl =~ pegLineTemplate:
+    result.tfile = extractFilename(matches[0])
+    result.tline = parseInt(matches[1])
+    result.tcolumn = parseInt(matches[2])
   if err =~ pegLineError:
     result.file = extractFilename(matches[0])
     result.line = parseInt(matches[1])
@@ -154,7 +167,7 @@ proc addResult(r: var TResults, test: TTest,
 proc cmpMsgs(r: var TResults, expected, given: TSpec, test: TTest) =
   if strip(expected.msg) notin strip(given.msg):
     r.addResult(test, expected.msg, given.msg, reMsgsDiffer)
-  elif extractFilename(expected.file) != extractFilename(given.file) and
+  elif expected.tfile == "" and extractFilename(expected.file) != extractFilename(given.file) and
       "internal error:" notin expected.msg:
     r.addResult(test, expected.file, given.file, reFilesDiffer)
   elif expected.line   != given.line   and expected.line   != 0 or
@@ -162,6 +175,14 @@ proc cmpMsgs(r: var TResults, expected, given: TSpec, test: TTest) =
     r.addResult(test, $expected.line & ':' & $expected.column,
                       $given.line    & ':' & $given.column,
                       reLinesDiffer)
+  elif expected.tfile != "" and extractFilename(expected.tfile) != extractFilename(given.tfile) and
+      "internal error:" notin expected.msg:
+    r.addResult(test, expected.tfile, given.tfile, reFilesDiffer)
+  elif expected.tline   != given.tline   and expected.tline   != 0 or
+       expected.tcolumn != given.tcolumn and expected.tcolumn != 0:
+    r.addResult(test, $expected.tline & ':' & $expected.tcolumn,
+                      $given.tline    & ':' & $given.tcolumn,
+                      reLinesDiffer)
   else:
     r.addResult(test, expected.msg, given.msg, reSuccess)
     inc(r.passed)