From 133d86a58e4a1652b10d66d48692e2bb8dd15f3b Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Tue, 27 Apr 2021 20:29:59 +0200 Subject: [PATCH] compat fixes evaluate name once only --- unittest2.nim | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/unittest2.nim b/unittest2.nim index 0fca314..2b85021 100644 --- a/unittest2.nim +++ b/unittest2.nim @@ -690,7 +690,7 @@ template suite*(name, body) {.dirty.} = template exceptionTypeName(e: typed): string = $e.name -template test*(name, body) = +template test*(name: string, body: untyped) = ## Define a single test case identified by `name`. ## ## .. code-block:: nim @@ -704,10 +704,7 @@ template test*(name, body) = ## .. code-block:: ## ## [OK] roses are red - bind shouldRun, checkpoints, testEnded, exceptionTypeName - withLock formattersLock: - {.gcsafe.}: - bind formatters + bind shouldRun, checkpoints, testStarted, testEnded, exceptionTypeName # `gensym` can't be in here because it's not a first-class pragma when paralleliseTests: @@ -747,7 +744,7 @@ template test*(name, body) = programResult = 1 let testResult = TestResult( suiteName: testSuiteName, - testName: name, + testName: testName, status: testStatusIMPL, duration: getMonoTime() - startTime ) @@ -755,11 +752,12 @@ template test*(name, body) = checkpoints = @[] let optionalTestSuiteName = when declared(testSuiteName): testSuiteName else: "" - if shouldRun(optionalTestSuiteName, name): + let tname = name + if shouldRun(optionalTestSuiteName, tname): when paralleliseTests: - flowVars.add(spawn runTest(optionalTestSuiteName, name)) + flowVars.add(spawn runTest(optionalTestSuiteName, tname)) else: - discard runTest(optionalTestSuiteName, name) + discard runTest(optionalTestSuiteName, tname) proc checkpoint*(msg: string) = ## Set a checkpoint identified by `msg`. Upon test failure all