add suiteTeardown() template

This commit is contained in:
Ștefan Talpalaru 2019-05-28 23:58:13 +02:00
parent b8ab4657e4
commit d01ed926d7
No known key found for this signature in database
GPG Key ID: CBF7934204F1B6F9
2 changed files with 16 additions and 4 deletions

View File

@ -116,6 +116,11 @@ suite "suite #2":
sleep(100)
check 1 == 1
suiteTeardown:
echo "suite teardown"
echo "this will be shown first"
# go back to the default one
clearOutputFormatters()

View File

@ -106,7 +106,8 @@
## expect(IndexError):
## discard v[4]
##
## echo "suite teardown: run once after the tests"
## suiteTeardown:
## echo "suite teardown: run once after the tests"
import locks, macros, sets, strutils, streams, times
@ -133,7 +134,7 @@ when paralleliseTests:
# (`flowVars` will be initialized in each child thread, when using nested tests, by the compiler)
# TODO: try getting rid of them when nim-0.20.0 is released
var flowVars {.threadvar.}: seq[FlowVarBase]
proc repeatableSync() =
proc repeatableSync*() =
sync()
for flowVar in flowVars:
blockUntil(flowVar)
@ -540,12 +541,20 @@ template suite*(name, body) {.dirty.} =
var testTeardownIMPLFlag {.used.} = true
template testTeardownIMPL: untyped {.dirty.} = teardownBody
template suiteTeardown(suiteTeardownBody: untyped) {.dirty, used.} =
var testSuiteTeardownIMPLFlag {.used.} = true
template testSuiteTeardownIMPL: untyped {.dirty.} = suiteTeardownBody
let testSuiteName {.used.} = name
ensureInitialized()
try:
suiteStarted(name)
body
when declared(testSuiteTeardownIMPLFlag):
when paralleliseTests:
repeatableSync()
testSuiteTeardownIMPL()
finally:
suiteEnded()
@ -605,8 +614,6 @@ template test*(name, body) =
)
testEnded(testResult)
checkpoints = @[]
# when running tests in parallel, "formatters" manipulation may occur in
# teardown(), so it needs to be after testEnded()
when declared(testTeardownIMPLFlag):
testTeardownIMPL()