Skip to content

Commit 6114df3

Browse files
authored
testament: error instead of silently overwrite a spec (#16166)
1 parent d29eddf commit 6114df3

File tree

5 files changed

+51
-27
lines changed

5 files changed

+51
-27
lines changed

testament/specs.nim

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#
99

1010
import sequtils, parseutils, strutils, os, streams, parsecfg,
11-
tables, hashes
11+
tables, hashes, sets
1212

1313
type TestamentData* = ref object
1414
# better to group globals under 1 object; could group the other ones here too
@@ -82,7 +82,7 @@ type
8282
tline*, tcolumn*: int
8383
exitCode*: int
8484
msg*: string
85-
ccodeCheck*: string
85+
ccodeCheck*: seq[string]
8686
maxCodeSize*: int
8787
err*: TResultEnum
8888
inCurrentBatch*: bool
@@ -244,11 +244,19 @@ proc parseSpec*(filename: string): TSpec =
244244
var ss = newStringStream(specStr)
245245
var p: CfgParser
246246
open(p, ss, filename, 1)
247+
var flags: HashSet[string]
247248
while true:
248249
var e = next(p)
249250
case e.kind
250251
of cfgKeyValuePair:
251-
case normalize(e.key)
252+
let key = e.key.normalize
253+
const whiteListMulti = ["disabled", "ccodecheck"]
254+
## list of flags that are correctly handled when passed multiple times
255+
## (instead of being overwritten)
256+
if key notin whiteListMulti:
257+
doAssert key notin flags, $(key, filename)
258+
flags.incl key
259+
case key
252260
of "action":
253261
case e.value.normalize
254262
of "compile":
@@ -298,7 +306,7 @@ proc parseSpec*(filename: string): TSpec =
298306
result.msg = e.value
299307
if result.action != actionRun:
300308
result.action = actionCompile
301-
of "errormsg", "errmsg":
309+
of "errormsg", "errmsg": # xxx just use errormsg, no need for such aliases
302310
result.msg = e.value
303311
result.action = actionReject
304312
of "nimout":
@@ -361,7 +369,7 @@ proc parseSpec*(filename: string): TSpec =
361369
else:
362370
result.cmd = e.value
363371
of "ccodecheck":
364-
result.ccodeCheck = e.value
372+
result.ccodeCheck.add e.value
365373
of "maxcodesize":
366374
discard parseInt(e.value, result.maxCodeSize)
367375
of "timeout":

testament/testament.nim

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,8 @@ proc codegenCheck(test: TTest, target: TTarget, spec: TSpec, expectedMsg: var st
402402
try:
403403
let genFile = generatedFile(test, target)
404404
let contents = readFile(genFile).string
405-
let check = spec.ccodeCheck
406-
if check.len > 0:
407-
if check[0] == '\\':
405+
for check in spec.ccodeCheck:
406+
if check.len > 0 and check[0] == '\\':
408407
# little hack to get 'match' support:
409408
if not contents.match(check.peg):
410409
given.err = reCodegenFailure

tests/casestmt/tcaseexpr1.nim

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
discard """
2-
errormsg: "type mismatch: got <string> but expected 'int'"
3-
line: 33
4-
file: "tcaseexpr1.nim"
5-
6-
errormsg: "not all cases are covered; missing: {C}"
7-
line: 27
8-
file: "tcaseexpr1.nim"
2+
cmd: "nim check $options $file"
3+
action: "reject"
4+
nimout: '''
5+
tcaseexpr1.nim(33, 10) Error: not all cases are covered; missing: {C}
6+
'''
97
"""
108

11-
# NOTE: This spec is wrong. Spec doesn't support multiple error
12-
# messages. The first one is simply overridden by the second one.
13-
# This just has never been noticed.
9+
#[
10+
# xxx make nimout comparison use nimoutCheck instead of:
11+
elif expected.nimout.len > 0 and expected.nimout.normalizeMsg notin given.nimout.normalizeMsg:
12+
13+
and then use nimout: '''
14+
tcaseexpr1.nim(33, 10) Error: not all cases are covered2; missing: {C}
15+
tcaseexpr1.nim(39, 12) Error: type mismatch: got <string> but expected 'int literal(10)'
16+
'''
17+
]#
18+
1419

20+
# line 20
1521
type
1622
E = enum A, B, C
1723

tests/exception/t13115.nim

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ discard """
22
exitcode: 1
33
targets: "c"
44
matrix: "-d:debug; -d:release"
5-
outputsub: '''t13115.nim(13) t13115
6-
Error: unhandled exception: This char is'''
75
outputsub: ''' and works fine! [Exception]'''
86
"""
97

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

13-
raise newException(Exception, msg)
11+
var msg = "This char is `" & '\0' & "` and works fine!"
12+
raise newException(Exception, msg)

tests/generics/tmetafield.nim

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
discard """
22
cmd: "nim check $options $file"
3-
errormsg: "'proc' is not a concrete type"
4-
errormsg: "'Foo' is not a concrete type."
5-
errormsg: "invalid type: 'proc' in this context: 'TBaseMed'"
3+
action: "reject"
4+
nimout: '''
5+
tmetafield.nim(26, 5) Error: 'proc' is not a concrete type; for a callback without parameters use 'proc()'
6+
tmetafield.nim(27, 5) Error: 'Foo' is not a concrete type
7+
tmetafield.nim(29, 5) Error: invalid type: 'proc' in this context: 'TBaseMed' for var
8+
'''
69
"""
710

11+
# bug #188
12+
13+
14+
15+
16+
17+
18+
19+
20+
# line 20
821
type
922
Foo[T] = object
1023
x: T
@@ -15,4 +28,3 @@ type
1528

1629
var a: TBaseMed
1730

18-
# issue 188

0 commit comments

Comments
 (0)