Skip to content

Commit

Permalink
tests: run more tests with all targets by default (#1118)
Browse files Browse the repository at this point in the history
Summary
=======
Enabled all test targets for some tests, fixed tests where necessary.
Better test coverage for JS and VM.

Details
=======
- Reordered the target category strings to be in alphabetical order to
make later adjustments easier.
- The  `targets`  key is removed for all tests except one to disable a
target where the target doesn't make
   sense.
-  `write(stdout, ...)`  is replaced with  `echo ...`  to support the JS
and VM targets.
- Some  `static: `  blocks have been removed and replaced with the VM
target where not specific to compile-time execution.
- Tests that fail but should work are marked as `knownIssue`.

part of #1075
  • Loading branch information
JackieWeiss authored Jan 20, 2024
1 parent 8056a57 commit c302619
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 43 deletions.
3 changes: 2 additions & 1 deletion testament/testament.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,8 @@ func nativeTarget(): TTarget {.inline.} =
func defaultTargets(category: Category): set[TTarget] =
const standardTargets = {nativeTarget()}
case category.string
of "lang", "lang_callable", "exception":
of "alias", "align", "ambsym", "arithm", "assert", "assign", "exception",
"lang", "lang_callable":
{targetC, targetJs, targetVM}
of "arc", "avr", "destructor", "distros", "dll", "gc", "osproc", "parallel",
"realtimeGC", "threads", "views", "valgrind":
Expand Down
3 changes: 2 additions & 1 deletion tests/align/talign.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
discard """
ccodeCheck: "\\i @'NIM_ALIGN(128) NI mylocal1' .*"
targets: "c"
labels: "pragma alignment generic"
description: '''
. First one is is for Azure. The keyword ``alignof`` only exists in ``c++11``
Expand All @@ -9,6 +8,8 @@ description: '''
. From https://github.com/nim-lang/Nim/issues/13122
{.align.} pragma is not applied if there is a generic field
'''
targets: "!js"
knownIssue.vm: "VM does not support casting a ptr to a uint"
"""

import globalalignas
Expand Down
9 changes: 5 additions & 4 deletions tests/arithm/tarithm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ description: '''
. It is expected that the order of operands on these operators should not
affect the operation.
'''
knownIssue.js: '''
The JavaScript backend generates non BigInteger integer literals for these
calculations resulting in a rounding error for integers over 2^53-1 due
to JavaScript using floating point numbers internally.
'''
"""

import typetraits
Expand Down Expand Up @@ -127,8 +132,6 @@ block tshr:
doAssert( (VI8 shr 1) == -4, "Actual: " & $(VI8 shr 1))

T()
static:
T()

block tUnsignedOps:
proc testUnsignedOps(): bool =
Expand All @@ -145,8 +148,6 @@ block tUnsignedOps:
result = true

doAssert testUnsignedOps()
static:
doAssert testUnsignedOps()

block issue_5216_bitwise_and:
doAssert (name typeof((0x0A'i8 and 0x7F'i32) shl 7'i32)) == "int32"
Expand Down
20 changes: 0 additions & 20 deletions tests/arithm/tashr.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
discard """
targets: "c js"
labels: "arithmetic bitwise shift int"
description: '''
. From https://github.com/nim-lang/Nim/issues/6255
Expand Down Expand Up @@ -33,22 +32,3 @@ block semfold_test:
doAssert ashr(-123'i32, 1) == -62
doAssert ashr(-123'i64, 1) == -62
doAssert ashr(-123 , 1) == -62

static: # VM test
doAssert ashr(-123'i8 , 1) == -62
doAssert ashr(-123'i16, 1) == -62
doAssert ashr(-123'i32, 1) == -62
doAssert ashr(-123'i64, 1) == -62
doAssert ashr(-123 , 1) == -62

var y1 = -123'i8
var y2 = -123'i16
var y3 = -123'i32
var y4 = -123'i64
var y5 = -123

doAssert ashr(y1, 1) == -62
doAssert ashr(y2, 1) == -62
doAssert ashr(y3, 1) == -62
doAssert ashr(y4, 1) == -62
doAssert ashr(y5, 1) == -62
2 changes: 0 additions & 2 deletions tests/arithm/tdiv.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
discard """
targets: "c js"
labels: "js arithmetic int"
description: '''
. Fix div uint64 without truncation for JS.
Expand All @@ -18,6 +17,5 @@ block divUint64:
doAssert z == 269113
doAssert a == 112130

static: divTest()
divTest()

10 changes: 6 additions & 4 deletions tests/assert/tassert.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
discard """
outputsub: "assertion failure!this shall be always written"
outputsub: '''assertion failure!
this shall be always written
'''
exitcode: "1"
"""
# test assert and exception handling
Expand All @@ -11,10 +13,10 @@ proc callC() = callA()
try:
callC()
except AssertionDefect:
write(stdout, "assertion failure!")
echo "assertion failure!"
except:
write(stdout, "unknown exception!")
echo "unknown exception!"
finally:
system.write(stdout, "this shall be always written")
echo "this shall be always written"

assert(false) #OUT assertion failure!this shall be always written
11 changes: 8 additions & 3 deletions tests/assert/tassert_c.nim
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
discard """
cmd: "nim $target $options --excessiveStackTrace:off $file"
matrix: "--excessiveStackTrace:off"
output: '''true'''
knownIssue.js vm:'''
JavaScript produces a different stacktrace output message than the C
target.
VM does not support 'getStackTrace' on an Exception.
'''
"""

const expected = """
tassert_c.nim(35) tassert_c
tassert_c.nim(34) foo
tassert_c.nim(40) tassert_c
tassert_c.nim(39) foo
assertions.nim(*) failedAssertImpl
assertions.nim(*) raiseAssert
fatal.nim(*) sysFatal"""
Expand Down
1 change: 1 addition & 0 deletions tests/assert/tunittests.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
discard """
output: ""
knownIssue.vm: "VM does not support 'copyMem'"
"""
import utemplates
import uclosures
8 changes: 4 additions & 4 deletions tests/assign/tassign.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ TEMP=C:\Programs\xyz\bin
8 5 0 0
pre test a:test b:1 c:2 haha:3
assignment test a:test b:1 c:2 haha:3
abc123
abc
123
'''
"""

Expand Down Expand Up @@ -72,7 +73,7 @@ block tcopy:
p = find(example, "=")
a = substr(example, 0, p-1)
b = substr(example, p+1)
writeLine(stdout, a & '=' & b)
echo a & '=' & b

main()

Expand Down Expand Up @@ -212,8 +213,7 @@ when false:
block tgeneric_assign_varargs:
template fatal(msgs: varargs[string]) =
for msg in msgs:
stdout.write(msg)
stdout.write('\n')
echo msg

fatal "abc", "123"

Expand Down
1 change: 0 additions & 1 deletion tests/assign/tcall_with_rvo.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
discard """
targets: "c js vm"
description: '''
Ensure that the return-value optimization (=RVO) is disabled where it would
affect observable semantics
Expand Down
3 changes: 1 addition & 2 deletions tests/assign/tin_place_construction.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
discard """
targets: "c js vm"
description: '''
Ensure that the in-place aggregate construction optimization doesn't affect
observable semantics
Expand Down Expand Up @@ -90,4 +89,4 @@ block object_callee:
var obj = Obj(a: proc (): int = 1)
# if in-place construction is used, a nil-access defect will occur
obj = Obj(a: nil, b: obj.a())
doAssert obj == Obj(a: nil, b: 1)
doAssert obj == Obj(a: nil, b: 1)
3 changes: 3 additions & 0 deletions tests/assign/tobject_assign.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ discard """
Regression test for assigning to an uninitialized `seq` slot that
has a type header
'''
knownIssue.vm: '''
'localtime' is not yet supported with the VM backend
'''
"""

# bug https://github.com/nim-lang/nim/issues/16706
Expand Down
2 changes: 1 addition & 1 deletion tests/assign/toverload_asgn2.nim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
discard """
output: '''i value 88
2aa'''
knownIssue: "possible issue where result is not treated as var Concrete in passAround"
knownIssue: "possible issue where result is not treated as var Concrete in passAround"
"""

import moverload_asgn2
Expand Down

0 comments on commit c302619

Please sign in to comment.