add tfile/tline assertions for template expansion file/line

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

View file

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

View file

@ -1,6 +1,6 @@
discard """ discard """
file: "tnot.nim" tfile: "tnot.nim"
line: 14 tline: 14
errormsg: "type mismatch" errormsg: "type mismatch"
""" """
# BUG: following compiles, but should not: # BUG: following compiles, but should not:
@ -17,6 +17,3 @@ proc main =
echo "No" echo "No"
main() main()

View file

@ -44,6 +44,8 @@ type
file*, cmd*: string file*, cmd*: string
outp*: string outp*: string
line*, column*: int line*, column*: int
tfile*: string
tline*, tcolumn*: int
exitCode*: int exitCode*: int
msg*: string msg*: string
ccodeCheck*: string ccodeCheck*: string
@ -116,6 +118,9 @@ proc parseSpec*(filename: string): TSpec =
of "file": result.file = e.value of "file": result.file = e.value
of "line": discard parseInt(e.value, result.line) of "line": discard parseInt(e.value, result.line)
of "column": discard parseInt(e.value, result.column) 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": of "output":
result.action = actionRun result.action = actionRun
result.outp = e.value result.outp = e.value

View file

@ -53,6 +53,8 @@ type
let let
pegLineError = pegLineError =
peg"{[^(]*} '(' {\d+} ', ' {\d+} ') ' ('Error') ':' \s* {.*}" peg"{[^(]*} '(' {\d+} ', ' {\d+} ') ' ('Error') ':' \s* {.*}"
pegLineTemplate =
peg"{[^(]*} '(' {\d+} ', ' {\d+} ') ' 'template/generic instantiation from here'.*"
pegOtherError = peg"'Error:' \s* {.*}" pegOtherError = peg"'Error:' \s* {.*}"
pegSuccess = peg"'Hint: operation successful'.*" pegSuccess = peg"'Hint: operation successful'.*"
pegOfInterest = pegLineError / pegOtherError pegOfInterest = pegLineError / pegOtherError
@ -66,6 +68,7 @@ proc callCompiler(cmdTemplate, filename, options: string,
let outp = p.outputStream let outp = p.outputStream
var suc = "" var suc = ""
var err = "" var err = ""
var tmpl = ""
var x = newStringOfCap(120) var x = newStringOfCap(120)
result.nimout = "" result.nimout = ""
while outp.readLine(x.TaintedString) or running(p): while outp.readLine(x.TaintedString) or running(p):
@ -73,6 +76,9 @@ proc callCompiler(cmdTemplate, filename, options: string,
if x =~ pegOfInterest: if x =~ pegOfInterest:
# `err` should contain the last error/warning message # `err` should contain the last error/warning message
err = x err = x
elif x =~ pegLineTemplate and err == "":
# `tmpl` contains the last template expansion before the error
tmpl = x
elif x =~ pegSuccess: elif x =~ pegSuccess:
suc = x suc = x
close(p) close(p)
@ -81,6 +87,13 @@ proc callCompiler(cmdTemplate, filename, options: string,
result.outp = "" result.outp = ""
result.line = 0 result.line = 0
result.column = 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: if err =~ pegLineError:
result.file = extractFilename(matches[0]) result.file = extractFilename(matches[0])
result.line = parseInt(matches[1]) 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) = proc cmpMsgs(r: var TResults, expected, given: TSpec, test: TTest) =
if strip(expected.msg) notin strip(given.msg): if strip(expected.msg) notin strip(given.msg):
r.addResult(test, expected.msg, given.msg, reMsgsDiffer) 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: "internal error:" notin expected.msg:
r.addResult(test, expected.file, given.file, reFilesDiffer) r.addResult(test, expected.file, given.file, reFilesDiffer)
elif expected.line != given.line and expected.line != 0 or 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, r.addResult(test, $expected.line & ':' & $expected.column,
$given.line & ':' & $given.column, $given.line & ':' & $given.column,
reLinesDiffer) 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: else:
r.addResult(test, expected.msg, given.msg, reSuccess) r.addResult(test, expected.msg, given.msg, reSuccess)
inc(r.passed) inc(r.passed)