Skip to content

Commit

Permalink
testament: error instead of silently overwrite a spec (nim-lang#16166)
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour authored and ardek66 committed Mar 26, 2021
1 parent b25767c commit 284b868
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 27 deletions.
18 changes: 13 additions & 5 deletions testament/specs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#

import sequtils, parseutils, strutils, os, streams, parsecfg,
tables, hashes
tables, hashes, sets

type TestamentData* = ref object
# better to group globals under 1 object; could group the other ones here too
Expand Down Expand Up @@ -82,7 +82,7 @@ type
tline*, tcolumn*: int
exitCode*: int
msg*: string
ccodeCheck*: string
ccodeCheck*: seq[string]
maxCodeSize*: int
err*: TResultEnum
inCurrentBatch*: bool
Expand Down Expand Up @@ -244,11 +244,19 @@ proc parseSpec*(filename: string): TSpec =
var ss = newStringStream(specStr)
var p: CfgParser
open(p, ss, filename, 1)
var flags: HashSet[string]
while true:
var e = next(p)
case e.kind
of cfgKeyValuePair:
case normalize(e.key)
let key = e.key.normalize
const whiteListMulti = ["disabled", "ccodecheck"]
## list of flags that are correctly handled when passed multiple times
## (instead of being overwritten)
if key notin whiteListMulti:
doAssert key notin flags, $(key, filename)
flags.incl key
case key
of "action":
case e.value.normalize
of "compile":
Expand Down Expand Up @@ -298,7 +306,7 @@ proc parseSpec*(filename: string): TSpec =
result.msg = e.value
if result.action != actionRun:
result.action = actionCompile
of "errormsg", "errmsg":
of "errormsg", "errmsg": # xxx just use errormsg, no need for such aliases
result.msg = e.value
result.action = actionReject
of "nimout":
Expand Down Expand Up @@ -361,7 +369,7 @@ proc parseSpec*(filename: string): TSpec =
else:
result.cmd = e.value
of "ccodecheck":
result.ccodeCheck = e.value
result.ccodeCheck.add e.value
of "maxcodesize":
discard parseInt(e.value, result.maxCodeSize)
of "timeout":
Expand Down
5 changes: 2 additions & 3 deletions testament/testament.nim
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,8 @@ proc codegenCheck(test: TTest, target: TTarget, spec: TSpec, expectedMsg: var st
try:
let genFile = generatedFile(test, target)
let contents = readFile(genFile).string
let check = spec.ccodeCheck
if check.len > 0:
if check[0] == '\\':
for check in spec.ccodeCheck:
if check.len > 0 and check[0] == '\\':
# little hack to get 'match' support:
if not contents.match(check.peg):
given.err = reCodegenFailure
Expand Down
26 changes: 16 additions & 10 deletions tests/casestmt/tcaseexpr1.nim
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
discard """
errormsg: "type mismatch: got <string> but expected 'int'"
line: 33
file: "tcaseexpr1.nim"
errormsg: "not all cases are covered; missing: {C}"
line: 27
file: "tcaseexpr1.nim"
cmd: "nim check $options $file"
action: "reject"
nimout: '''
tcaseexpr1.nim(33, 10) Error: not all cases are covered; missing: {C}
'''
"""

# NOTE: This spec is wrong. Spec doesn't support multiple error
# messages. The first one is simply overridden by the second one.
# This just has never been noticed.
#[
# 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
type
E = enum A, B, C

Expand Down
9 changes: 4 additions & 5 deletions tests/exception/t13115.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ discard """
exitcode: 1
targets: "c"
matrix: "-d:debug; -d:release"
outputsub: '''t13115.nim(13) t13115
Error: unhandled exception: This char is'''
outputsub: ''' and works fine! [Exception]'''
"""

const b_null: char = 0.char
var msg = "This char is `" & $b_null & "` and works fine!"
# bug #13115
# xxx bug: doesn't yet work for cpp

raise newException(Exception, msg)
var msg = "This char is `" & '\0' & "` and works fine!"
raise newException(Exception, msg)
20 changes: 16 additions & 4 deletions tests/generics/tmetafield.nim
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
discard """
cmd: "nim check $options $file"
errormsg: "'proc' is not a concrete type"
errormsg: "'Foo' is not a concrete type."
errormsg: "invalid type: 'proc' in this context: 'TBaseMed'"
action: "reject"
nimout: '''
tmetafield.nim(26, 5) Error: 'proc' is not a concrete type; for a callback without parameters use 'proc()'
tmetafield.nim(27, 5) Error: 'Foo' is not a concrete type
tmetafield.nim(29, 5) Error: invalid type: 'proc' in this context: 'TBaseMed' for var
'''
"""

# bug #188








# line 20
type
Foo[T] = object
x: T
Expand All @@ -15,4 +28,3 @@ type

var a: TBaseMed

# issue 188

0 comments on commit 284b868

Please sign in to comment.