Skip to content

Commit

Permalink
testament: error instead of silently ignore invalid targets; remove p…
Browse files Browse the repository at this point in the history
…ointless 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 <[email protected]>
  • Loading branch information
timotheecour and Araq authored Dec 14, 2020
1 parent 5514b29 commit 7e1ae35
Show file tree
Hide file tree
Showing 24 changed files with 33 additions and 39 deletions.
9 changes: 6 additions & 3 deletions doc/testament.rst
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,11 @@ Example "template" **to edit** and write a Testament unittest:
# Timeout seconds to run the test. Fractional values are supported.
timeout: 1.5
# Targets to run the test into (C, C++, JavaScript, etc).
target: "c js"
# Targets to run the test into (c, cpp, objc, 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
# is permitted.
Expand Down Expand Up @@ -221,7 +224,7 @@ JavaScript tests:
.. code-block:: nim
discard """
target: "js"
targets: "js"
"""
when defined(js):
import jsconsole
Expand Down
20 changes: 6 additions & 14 deletions testament/specs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ proc parseTargets*(value: string): set[TTarget] =
of "cpp", "c++": result.incl(targetCpp)
of "objc": result.incl(targetObjC)
of "js": result.incl(targetJS)
else: echo "target ignored: " & v
else: raise newException(ValueError, "invalid target: '$#'" % v)

proc addLine*(self: var string; a: string) =
self.add a
Expand Down Expand Up @@ -377,19 +377,11 @@ proc parseSpec*(filename: string): TSpec =
result.timeout = parseFloat(e.value)
except ValueError:
result.parseErrors.addLine "cannot interpret as a float: ", e.value
of "target", "targets":
for v in e.value.normalize.splitWhitespace:
case v
of "c":
result.targets.incl(targetC)
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 "targets", "target":
try:
result.targets.incl parseTargets(e.value)
except ValueError as e:
result.parseErrors.addLine e.msg
of "matrix":
for v in e.value.split(';'):
result.matrix.add(v.strip)
Expand Down
2 changes: 1 addition & 1 deletion tests/align/talign.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
discard """
ccodeCheck: "\\i @'NIM_ALIGN(128) NI mylocal1' .*"
target: "c cpp"
targets: "c cpp"
output: "align ok"
"""

Expand Down
2 changes: 1 addition & 1 deletion tests/arc/trtree.nim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
discard """
output: '''1 [2, 3, 4, 7]
[0, 0]'''
target: "c"
targets: "c"
joinable: false
disabled: 32bit
cmd: "nim c --gc:arc $file"
Expand Down
2 changes: 1 addition & 1 deletion tests/ccgbugs/tmissingvolatile.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ discard """
output: "1"
cmd: r"nim c --hints:on $options -d:release $file"
ccodecheck: "'NI volatile state;'"
target: "C"
targets: "c"
"""

# bug #1539
Expand Down
2 changes: 1 addition & 1 deletion tests/ccgbugs/tprogmem.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ discard """
output: "5"
cmd: r"nim c --hints:on $options -d:release $file"
ccodecheck: "'/*PROGMEM*/ myLetVariable = {'"
target: "C"
targets: "c"
"""

var myLetVariable {.exportc, codegenDecl: "$# /*PROGMEM*/ $#".} = [1, 2, 3]
Expand Down
2 changes: 1 addition & 1 deletion tests/ccgbugs2/tinefficient_const_table.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ of
words'''
cmd: r"nim c --hints:on $options -d:release $file"
ccodecheck: "! @'genericSeqAssign'"
target: "c"
targets: "c"
"""

# bug #4354
Expand Down
2 changes: 1 addition & 1 deletion tests/closure/tclosure.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
discard """
target: "c"
targets: "c"
output: '''
1 3 6 11 20 foo
foo88
Expand Down
1 change: 0 additions & 1 deletion tests/compiler/tcppCompileToNamespace.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
discard """
cmd: "nim cpp --cppCompileToNamespace:foo $options -r $file"
target: cpp
"""

# Theoretically nim could just ignore the flag cppCompileToNamespace
Expand Down
2 changes: 1 addition & 1 deletion tests/coroutines/texceptions.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
discard """
target: "c"
targets: "c"
disabled: true
"""

Expand Down
2 changes: 1 addition & 1 deletion tests/coroutines/tgc.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
discard """
target: "c"
targets: "c"
"""

import coro
Expand Down
2 changes: 1 addition & 1 deletion tests/coroutines/titerators.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
discard """
target: "c"
targets: "c"
disabled: true
"""

Expand Down
2 changes: 1 addition & 1 deletion tests/coroutines/twait.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
discard """
output: "Exit 1\nExit 2"
target: "c"
targets: "c"
"""
import coro

Expand Down
2 changes: 1 addition & 1 deletion tests/cpp/tevalorder.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ discard """
output: '''0
1
2'''
target: "cpp"
targets: "cpp"
"""

# bug #8202
Expand Down
2 changes: 1 addition & 1 deletion tests/destructor/tmove_objconstr.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test destroyed 0
4
Pony is dying!'''
joinable: false
target: "C"
targets: "c"
"""

# bug #4214
Expand Down
2 changes: 1 addition & 1 deletion tests/destructor/tuse_result_prevents_sinks.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
discard """
output: ""
target: "C"
targets: "c"
"""

# bug #9594
Expand Down
2 changes: 1 addition & 1 deletion tests/exception/t9657.nim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
discard """
action: run
exitcode: 1
target: "c cpp"
targets: "c cpp"
disabled: "openbsd"
disabled: "netbsd"
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/flags/tgenscript.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
discard """
target: "c"
targets: "c"
action: compile
"""

Expand Down
2 changes: 1 addition & 1 deletion tests/iter/titervaropenarray.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
discard """
output: "123"
targets: "C"
targets: "c"
"""
# Try to break the transformation pass:
iterator iterAndZero(a: var openArray[int]): int =
Expand Down
2 changes: 1 addition & 1 deletion tests/objects/tobjcov.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
discard """
action: compile
target: "c"
targets: "c"
"""

# Covariance is not type safe:
Expand Down
2 changes: 1 addition & 1 deletion tests/stdlib/t10231.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
discard """
target: cpp
targets: "cpp"
action: run
exitcode: 0
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/stdlib/thashes.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
discard """
targets: '''c c++ js'''
targets: "c cpp js"
"""

import hashes
Expand Down
2 changes: 1 addition & 1 deletion tests/stdlib/ttimes.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
discard """
target: "c js"
targets: "c js"
"""

import times, strutils, unittest
Expand Down
2 changes: 1 addition & 1 deletion tests/system/tatomics1.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
discard """
target: "c cpp js"
targets: "c cpp js"
"""

var x = 10
Expand Down

0 comments on commit 7e1ae35

Please sign in to comment.