reorder code (#9)

declare checkpoint/fail before use to avoid random compile errors
This commit is contained in:
Jacek Sieka 2021-08-16 15:10:04 +02:00 committed by GitHub
parent 91d4eaa4cc
commit 4c2ce01e34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 60 additions and 60 deletions

View File

@ -705,6 +705,66 @@ template suite*(name, body) {.dirty.} =
template exceptionTypeName(e: typed): string = $e.name
template checkpoint*(msg: string) =
## Set a checkpoint identified by `msg`. Upon test failure all
## checkpoints encountered so far are printed out. Example:
##
## .. code-block:: nim
##
## checkpoint("Checkpoint A")
## check((42, "the Answer to life and everything") == (1, "a"))
## checkpoint("Checkpoint B")
##
## outputs "Checkpoint A" once it fails.
checkpoints.add(msg)
# TODO: add support for something like SCOPED_TRACE from Google Test
template fail* =
## Print out the checkpoints encountered so far and quit if ``abortOnError``
## is true. Otherwise, erase the checkpoints and indicate the test has
## failed (change exit code and test status). This template is useful
## for debugging, but is otherwise mostly used internally. Example:
##
## .. code-block:: nim
##
## checkpoint("Checkpoint A")
## complicatedProcInThread()
## fail()
##
## outputs "Checkpoint A" before quitting.
when declared(testStatusIMPL):
testStatusIMPL = TestStatus.FAILED
else:
programResult = 1
withLock formattersLock:
{.gcsafe.}:
for formatter in formatters:
when declared(stackTrace):
formatter.failureOccurred(checkpoints, stackTrace)
else:
formatter.failureOccurred(checkpoints, "")
if abortOnError: quit(1)
checkpoints = @[]
template skip* =
## Mark the test as skipped. Should be used directly
## in case when it is not possible to perform test
## for reasons depending on outer environment,
## or certain application logic conditions or configurations.
## The test code is still executed.
##
## .. code-block:: nim
##
## if not isGLContextCreated():
## skip()
bind checkpoints
testStatusIMPL = TestStatus.SKIPPED
checkpoints = @[]
template test*(name: string, body: untyped) =
## Define a single test case identified by `name`.
##
@ -774,66 +834,6 @@ template test*(name: string, body: untyped) =
else:
discard runTest(optionalTestSuiteName, tname)
proc checkpoint*(msg: string) =
## Set a checkpoint identified by `msg`. Upon test failure all
## checkpoints encountered so far are printed out. Example:
##
## .. code-block:: nim
##
## checkpoint("Checkpoint A")
## check((42, "the Answer to life and everything") == (1, "a"))
## checkpoint("Checkpoint B")
##
## outputs "Checkpoint A" once it fails.
checkpoints.add(msg)
# TODO: add support for something like SCOPED_TRACE from Google Test
template fail* =
## Print out the checkpoints encountered so far and quit if ``abortOnError``
## is true. Otherwise, erase the checkpoints and indicate the test has
## failed (change exit code and test status). This template is useful
## for debugging, but is otherwise mostly used internally. Example:
##
## .. code-block:: nim
##
## checkpoint("Checkpoint A")
## complicatedProcInThread()
## fail()
##
## outputs "Checkpoint A" before quitting.
when declared(testStatusIMPL):
testStatusIMPL = TestStatus.FAILED
else:
programResult = 1
withLock formattersLock:
{.gcsafe.}:
for formatter in formatters:
when declared(stackTrace):
formatter.failureOccurred(checkpoints, stackTrace)
else:
formatter.failureOccurred(checkpoints, "")
if abortOnError: quit(1)
checkpoints = @[]
template skip* =
## Mark the test as skipped. Should be used directly
## in case when it is not possible to perform test
## for reasons depending on outer environment,
## or certain application logic conditions or configurations.
## The test code is still executed.
##
## .. code-block:: nim
##
## if not isGLContextCreated():
## skip()
bind checkpoints
testStatusIMPL = TestStatus.SKIPPED
checkpoints = @[]
{.pop.} # raises: [Defect]
macro check*(conditions: untyped): untyped =