compat fixes

evaluate name once only
This commit is contained in:
Jacek Sieka 2021-04-27 20:29:59 +02:00
parent 0bff52a779
commit 133d86a58e
No known key found for this signature in database
GPG Key ID: A1B09461ABB656B8
1 changed files with 7 additions and 9 deletions

View File

@ -690,7 +690,7 @@ template suite*(name, body) {.dirty.} =
template exceptionTypeName(e: typed): string = $e.name 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`. ## Define a single test case identified by `name`.
## ##
## .. code-block:: nim ## .. code-block:: nim
@ -704,10 +704,7 @@ template test*(name, body) =
## .. code-block:: ## .. code-block::
## ##
## [OK] roses are red ## [OK] roses are red
bind shouldRun, checkpoints, testEnded, exceptionTypeName bind shouldRun, checkpoints, testStarted, testEnded, exceptionTypeName
withLock formattersLock:
{.gcsafe.}:
bind formatters
# `gensym` can't be in here because it's not a first-class pragma # `gensym` can't be in here because it's not a first-class pragma
when paralleliseTests: when paralleliseTests:
@ -747,7 +744,7 @@ template test*(name, body) =
programResult = 1 programResult = 1
let testResult = TestResult( let testResult = TestResult(
suiteName: testSuiteName, suiteName: testSuiteName,
testName: name, testName: testName,
status: testStatusIMPL, status: testStatusIMPL,
duration: getMonoTime() - startTime duration: getMonoTime() - startTime
) )
@ -755,11 +752,12 @@ template test*(name, body) =
checkpoints = @[] checkpoints = @[]
let optionalTestSuiteName = when declared(testSuiteName): testSuiteName else: "" let optionalTestSuiteName = when declared(testSuiteName): testSuiteName else: ""
if shouldRun(optionalTestSuiteName, name): let tname = name
if shouldRun(optionalTestSuiteName, tname):
when paralleliseTests: when paralleliseTests:
flowVars.add(spawn runTest(optionalTestSuiteName, name)) flowVars.add(spawn runTest(optionalTestSuiteName, tname))
else: else:
discard runTest(optionalTestSuiteName, name) discard runTest(optionalTestSuiteName, tname)
proc checkpoint*(msg: string) = proc checkpoint*(msg: string) =
## Set a checkpoint identified by `msg`. Upon test failure all ## Set a checkpoint identified by `msg`. Upon test failure all