add tfile/tline assertions for template expansion file/line

This commit is contained in:
Aman Gupta
2015-10-06 15:47:07 -07:00
parent eea8d604d0
commit 2240fd3f3f
4 changed files with 31 additions and 8 deletions

View File

@@ -1,6 +1,6 @@
discard """
file: "tenummix.nim"
line: 11
tfile: "tenummix.nim"
tline: 11
errormsg: "type mismatch"
"""

View File

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

View File

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

View File

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