summary refs log tree commit diff stats
path: root/testament
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2020-11-29 10:42:50 -0800
committerGitHub <noreply@github.com>2020-11-29 10:42:50 -0800
commit6114df3c24e9c23bfbdbaa204bb100de9d170995 (patch)
treeaaabc7a0e5ecc6ea6ba5572fef469e54f94fb876 /testament
parentd29eddf92a1b8147c4709fd828f77152c1f3aab2 (diff)
downloadNim-6114df3c24e9c23bfbdbaa204bb100de9d170995.tar.gz
testament: error instead of silently overwrite a spec (#16166)
Diffstat (limited to 'testament')
-rw-r--r--testament/specs.nim18
-rw-r--r--testament/testament.nim5
2 files changed, 15 insertions, 8 deletions
diff --git a/testament/specs.nim b/testament/specs.nim
index c60ed7e20..d2f37b96c 100644
--- a/testament/specs.nim
+++ b/testament/specs.nim
@@ -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
@@ -82,7 +82,7 @@ type
     tline*, tcolumn*: int
     exitCode*: int
     msg*: string
-    ccodeCheck*: string
+    ccodeCheck*: seq[string]
     maxCodeSize*: int
     err*: TResultEnum
     inCurrentBatch*: bool
@@ -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":
@@ -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":
@@ -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":
diff --git a/testament/testament.nim b/testament/testament.nim
index c014a79a6..f2ac9c338 100644
--- a/testament/testament.nim
+++ b/testament/testament.nim
@@ -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