testament: error instead of silently ignore invalid targets; remove pointless alias target vs targets; document matrix; DRY (#16343)

* testament: error instead of silently ignore invalid targets
* s/target/targets/
* fix test; refs #16344
* address comments
* Update testament/specs.nim

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
This commit is contained in:
Timothee Cour 2020-12-14 01:58:29 -08:00 • committed by GitHub
commit 7e1ae35195
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 33 additions and 39 deletions

View file

@ -152,8 +152,11 @@ Example "template" **to edit** and write a Testament unittest:
# Timeout seconds to run the test. Fractional values are supported. # Timeout seconds to run the test. Fractional values are supported.
timeout: 1.5 timeout: 1.5
# Targets to run the test into (C, C++, JavaScript, etc). # Targets to run the test into (c, cpp, objc, js).
target: "c js" targets: "c js"
# flags with which to run the test, delimited by `;`
matrix: "; -d:release; -d:caseFoo -d:release"
# Conditions that will skip this test. Use of multiple "disabled" clauses # Conditions that will skip this test. Use of multiple "disabled" clauses
# is permitted. # is permitted.
@ -221,7 +224,7 @@ JavaScript tests:
.. code-block:: nim .. code-block:: nim
discard """ discard """
target: "js" targets: "js"
""" """
when defined(js): when defined(js):
import jsconsole import jsconsole

View file

@ -218,7 +218,7 @@ proc parseTargets*(value: string): set[TTarget] =
of "cpp", "c++": result.incl(targetCpp) of "cpp", "c++": result.incl(targetCpp)
of "objc": result.incl(targetObjC) of "objc": result.incl(targetObjC)
of "js": result.incl(targetJS) of "js": result.incl(targetJS)
else: echo "target ignored: " & v else: raise newException(ValueError, "invalid target: '$#'" % v)
proc addLine*(self: var string; a: string) = proc addLine*(self: var string; a: string) =
self.add a self.add a
@ -377,19 +377,11 @@ proc parseSpec*(filename: string): TSpec =
result.timeout = parseFloat(e.value) result.timeout = parseFloat(e.value)
except ValueError: except ValueError:
result.parseErrors.addLine "cannot interpret as a float: ", e.value result.parseErrors.addLine "cannot interpret as a float: ", e.value
of "target", "targets": of "targets", "target":
for v in e.value.normalize.splitWhitespace: try:
case v result.targets.incl parseTargets(e.value)
of "c": except ValueError as e:
result.targets.incl(targetC) result.parseErrors.addLine e.msg
of "cpp", "c++":
result.targets.incl(targetCpp)
of "objc":
result.targets.incl(targetObjC)
of "js":
result.targets.incl(targetJS)
else:
result.parseErrors.addLine "cannot interpret as a target: ", e.value
of "matrix": of "matrix":
for v in e.value.split(';'): for v in e.value.split(';'):
result.matrix.add(v.strip) result.matrix.add(v.strip)

View file

@ -1,6 +1,6 @@
discard """ discard """
ccodeCheck: "\\i @'NIM_ALIGN(128) NI mylocal1' .*" ccodeCheck: "\\i @'NIM_ALIGN(128) NI mylocal1' .*"
target: "c cpp" targets: "c cpp"
output: "align ok" output: "align ok"
""" """

View file

@ -1,7 +1,7 @@
discard """ discard """
output: '''1 [2, 3, 4, 7] output: '''1 [2, 3, 4, 7]
[0, 0]''' [0, 0]'''
target: "c" targets: "c"
joinable: false joinable: false
disabled: 32bit disabled: 32bit
cmd: "nim c --gc:arc $file" cmd: "nim c --gc:arc $file"

View file

@ -2,7 +2,7 @@ discard """
output: "1" output: "1"
cmd: r"nim c --hints:on $options -d:release $file" cmd: r"nim c --hints:on $options -d:release $file"
ccodecheck: "'NI volatile state;'" ccodecheck: "'NI volatile state;'"
target: "C" targets: "c"
""" """
# bug #1539 # bug #1539

View file

@ -2,7 +2,7 @@ discard """
output: "5" output: "5"
cmd: r"nim c --hints:on $options -d:release $file" cmd: r"nim c --hints:on $options -d:release $file"
ccodecheck: "'/*PROGMEM*/ myLetVariable = {'" ccodecheck: "'/*PROGMEM*/ myLetVariable = {'"
target: "C" targets: "c"
""" """
var myLetVariable {.exportc, codegenDecl: "$# /*PROGMEM*/ $#".} = [1, 2, 3] var myLetVariable {.exportc, codegenDecl: "$# /*PROGMEM*/ $#".} = [1, 2, 3]

View file

@ -6,7 +6,7 @@ of
words''' words'''
cmd: r"nim c --hints:on $options -d:release $file" cmd: r"nim c --hints:on $options -d:release $file"
ccodecheck: "! @'genericSeqAssign'" ccodecheck: "! @'genericSeqAssign'"
target: "c" targets: "c"
""" """
# bug #4354 # bug #4354

View file

@ -1,5 +1,5 @@
discard """ discard """
target: "c" targets: "c"
output: ''' output: '''
1 3 6 11 20 foo 1 3 6 11 20 foo
foo88 foo88

View file

@ -1,6 +1,5 @@
discard """ discard """
cmd: "nim cpp --cppCompileToNamespace:foo $options -r $file" cmd: "nim cpp --cppCompileToNamespace:foo $options -r $file"
target: cpp
""" """
# Theoretically nim could just ignore the flag cppCompileToNamespace # Theoretically nim could just ignore the flag cppCompileToNamespace

View file

@ -1,5 +1,5 @@
discard """ discard """
target: "c" targets: "c"
disabled: true disabled: true
""" """

View file

@ -1,5 +1,5 @@
discard """ discard """
target: "c" targets: "c"
""" """
import coro import coro

View file

@ -1,5 +1,5 @@
discard """ discard """
target: "c" targets: "c"
disabled: true disabled: true
""" """

View file

@ -1,6 +1,6 @@
discard """ discard """
output: "Exit 1\nExit 2" output: "Exit 1\nExit 2"
target: "c" targets: "c"
""" """
import coro import coro

View file

@ -2,7 +2,7 @@ discard """
output: '''0 output: '''0
1 1
2''' 2'''
target: "cpp" targets: "cpp"
""" """
# bug #8202 # bug #8202

View file

@ -8,7 +8,7 @@ test destroyed 0
4 4
Pony is dying!''' Pony is dying!'''
joinable: false joinable: false
target: "C" targets: "c"
""" """
# bug #4214 # bug #4214

View file

@ -1,6 +1,6 @@
discard """ discard """
output: "" output: ""
target: "C" targets: "c"
""" """
# bug #9594 # bug #9594

View file

@ -1,7 +1,7 @@
discard """ discard """
action: run action: run
exitcode: 1 exitcode: 1
target: "c cpp" targets: "c cpp"
disabled: "openbsd" disabled: "openbsd"
disabled: "netbsd" disabled: "netbsd"
""" """

View file

@ -1,5 +1,5 @@
discard """ discard """
target: "c" targets: "c"
action: compile action: compile
""" """

View file

@ -1,6 +1,6 @@
discard """ discard """
output: "123" output: "123"
targets: "C" targets: "c"
""" """
# Try to break the transformation pass: # Try to break the transformation pass:
iterator iterAndZero(a: var openArray[int]): int = iterator iterAndZero(a: var openArray[int]): int =

View file

@ -1,6 +1,6 @@
discard """ discard """
action: compile action: compile
target: "c" targets: "c"
""" """
# Covariance is not type safe: # Covariance is not type safe:

View file

@ -1,5 +1,5 @@
discard """ discard """
target: cpp targets: "cpp"
action: run action: run
exitcode: 0 exitcode: 0
""" """

View file

@ -1,5 +1,5 @@
discard """ discard """
targets: '''c c++ js''' targets: "c cpp js"
""" """
import hashes import hashes

View file

@ -1,5 +1,5 @@
discard """ discard """
target: "c js" targets: "c js"
""" """
import times, strutils, unittest import times, strutils, unittest

View file

@ -1,5 +1,5 @@
discard """ discard """
target: "c cpp js" targets: "c cpp js"
""" """
var x = 10 var x = 10