From 04f3df4c87e8ba9efc26fa4faed8e3b6cbaa6e93 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Tue, 14 May 2024 17:33:08 +0800 Subject: [PATCH] fixes testament matrix doesn't work with other backends which left many JS tests untested (#23592) Targets are not changes, which means the C binary is actually tested for JS backend --- testament/testament.nim | 27 ++++++++++++++++++++++++--- tests/int/tints.nim | 2 -- tests/stdlib/thashes.nim | 3 ++- tests/stdlib/trandom.nim | 5 ++++- tests/stdlib/tstrutils.nim | 2 +- tests/system/tdollars.nim | 6 +++--- 6 files changed, 34 insertions(+), 11 deletions(-) diff --git a/testament/testament.nim b/testament/testament.nim index e0a200e29b..1e892e6367 100644 --- a/testament/testament.nim +++ b/testament/testament.nim @@ -10,9 +10,12 @@ ## This program verifies Nim against the testcases. import - strutils, pegs, os, osproc, streams, json, std/exitprocs, - backend, parseopt, specs, htmlgen, browsers, terminal, - algorithm, times, azure, intsets, macros + std/[strutils, pegs, os, osproc, streams, json, + parseopt, browsers, terminal, exitprocs, + algorithm, times, intsets, macros] + +import backend, specs, azure, htmlgen + from std/sugar import dup import compiler/nodejs import lib/stdtest/testutils @@ -528,6 +531,23 @@ proc testSpecHelper(r: var TResults, test: var TTest, expected: TSpec, "exitcode: " & $given.exitCode & "\n\nOutput:\n" & given.nimout, reExitcodesDiffer) + + +proc changeTarget(extraOptions: string; defaultTarget: TTarget): TTarget = + result = defaultTarget + var p = parseopt.initOptParser(extraOptions) + + while true: + parseopt.next(p) + case p.kind + of cmdEnd: break + of cmdLongOption, cmdShortOption: + if p.key == "b" or p.key == "backend": + result = parseEnum[TTarget](p.val.normalize) + # chooses the last one + else: + discard + proc targetHelper(r: var TResults, test: TTest, expected: TSpec, extraOptions: string) = for target in expected.targets: inc(r.total) @@ -540,6 +560,7 @@ proc targetHelper(r: var TResults, test: TTest, expected: TSpec, extraOptions: s else: let nimcache = nimcacheDir(test.name, test.options, target) var testClone = test + let target = changeTarget(extraOptions, target) testSpecHelper(r, testClone, expected, target, extraOptions, nimcache) proc testSpec(r: var TResults, test: TTest, targets: set[TTarget] = {}) = diff --git a/tests/int/tints.nim b/tests/int/tints.nim index 5c071c21dd..df72ec80ab 100644 --- a/tests/int/tints.nim +++ b/tests/int/tints.nim @@ -1,6 +1,5 @@ discard """ matrix: "; --backend:js --jsbigint64:off; --backend:js --jsbigint64:on" - targets: "c js" output: ''' 0 0 0 0 @@ -8,7 +7,6 @@ Success''' """ # Test the different integer operations -# TODO: fixme --backend:js cannot change targets!!! import std/private/jsutils diff --git a/tests/stdlib/thashes.nim b/tests/stdlib/thashes.nim index b6fbbbdb7c..3974b01c81 100644 --- a/tests/stdlib/thashes.nim +++ b/tests/stdlib/thashes.nim @@ -31,7 +31,8 @@ block hashes: doAssert hashWangYi1(123) == wy123 const wyNeg123 = hashWangYi1(-123) doAssert wyNeg123 != 0 - doAssert hashWangYi1(-123) == wyNeg123 + when not defined(js): # TODO: fixme it doesn't work for JS + doAssert hashWangYi1(-123) == wyNeg123 # "hashIdentity value incorrect at 456" diff --git a/tests/stdlib/trandom.nim b/tests/stdlib/trandom.nim index 920d429d4f..2e61312fdf 100644 --- a/tests/stdlib/trandom.nim +++ b/tests/stdlib/trandom.nim @@ -297,6 +297,9 @@ block: # bug #22360 inc fc when defined(js): - doAssert (tc, fc) == (483, 517), $(tc, fc) + when compileOption("jsbigint64"): + doAssert (tc, fc) == (517, 483), $(tc, fc) + else: + doAssert (tc, fc) == (515, 485), $(tc, fc) else: doAssert (tc, fc) == (510, 490), $(tc, fc) diff --git a/tests/stdlib/tstrutils.nim b/tests/stdlib/tstrutils.nim index 9cc65f218b..9937126f94 100644 --- a/tests/stdlib/tstrutils.nim +++ b/tests/stdlib/tstrutils.nim @@ -527,9 +527,9 @@ template main() = block: # toHex doAssert(toHex(100i16, 32) == "00000000000000000000000000000064") - doAssert(toHex(-100i16, 32) == "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9C") whenJsNoBigInt64: discard do: + doAssert(toHex(-100i16, 32) == "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9C") doAssert(toHex(high(uint64)) == "FFFFFFFFFFFFFFFF") doAssert(toHex(high(uint64), 16) == "FFFFFFFFFFFFFFFF") doAssert(toHex(high(uint64), 32) == "0000000000000000FFFFFFFFFFFFFFFF") diff --git a/tests/system/tdollars.nim b/tests/system/tdollars.nim index 39337cca77..61aa185349 100644 --- a/tests/system/tdollars.nim +++ b/tests/system/tdollars.nim @@ -109,10 +109,10 @@ block: # if `uint8(a1)` changes meaning to `cast[uint8](a1)` in future, update this test; # until then, this is the correct semantics. let a3 = $a2 - doAssert a2 < 3 - doAssert a3 == "-1" + doAssert a2 == 255'u8 + doAssert a3 == "255" proc intToStr(a: uint8): cstring {.importjs: "(# + \"\")".} - doAssert $intToStr(a2) == "-1" + doAssert $intToStr(a2) == "255" else: block: let x = -1'i8