mirror of
https://github.com/status-im/nim-unittest2.git
synced 2025-02-17 20:36:24 +00:00
fix: issue 43
This commit is contained in:
parent
e96f321503
commit
e8a3b81133
@ -34,12 +34,14 @@ suite "PR #35":
|
||||
doAssert(true)
|
||||
|
||||
teardown:
|
||||
if testStatusIMPL != TestStatus.FAILED:
|
||||
if testStatusIMPL != TestStatus.FAILED or testStatusObj.status != TestStatus.FAILED:
|
||||
testStatusIMPL = TestStatus.FAILED
|
||||
testStatusObj.status = TestStatus.FAILED
|
||||
exitProcs.setProgramResult(QuitFailure)
|
||||
debugEcho "PR #35 test FAILED"
|
||||
else:
|
||||
testStatusIMPL = TestStatus.OK
|
||||
testStatusObj.status = TestStatus.OK
|
||||
exitProcs.setProgramResult(QuitSuccess)
|
||||
|
||||
test "something":
|
||||
@ -238,3 +240,18 @@ suite "break should works inside test body":
|
||||
number = 3
|
||||
test "step three":
|
||||
check number == 2
|
||||
|
||||
suite "Issue #43":
|
||||
proc p = fail()
|
||||
|
||||
teardown:
|
||||
if testStatusObj.status != TestStatus.FAILED:
|
||||
testStatusObj.status = TestStatus.FAILED
|
||||
exitProcs.setProgramResult(QuitFailure)
|
||||
debugEcho "Issue #43 test FAILED"
|
||||
else:
|
||||
testStatusObj.status = TestStatus.OK
|
||||
exitProcs.setProgramResult(QuitSuccess)
|
||||
|
||||
test "procedure defined outside the test scope fails":
|
||||
p()
|
||||
|
@ -256,6 +256,10 @@ type
|
||||
suites: seq[JUnitSuite]
|
||||
currentSuite: int
|
||||
|
||||
TestStatusObject = object
|
||||
enabled: bool
|
||||
status: TestStatus
|
||||
|
||||
# TODO these globals are threadvar so as to avoid gc-safety-issues - this should
|
||||
# probably be resolved in a better way down the line specially since we
|
||||
# don't support threads _really_
|
||||
@ -271,6 +275,7 @@ var
|
||||
testsFilters {.threadvar.}: HashSet[string]
|
||||
|
||||
currentSuite {.threadvar.}: string
|
||||
testStatusObj* {.threadvar.}: TestStatusObject
|
||||
|
||||
when collect:
|
||||
var
|
||||
@ -1027,6 +1032,7 @@ template fail* =
|
||||
else:
|
||||
when declared(testStatusIMPL):
|
||||
testStatusIMPL = TestStatus.FAILED
|
||||
testStatusObj.status = TestStatus.FAILED
|
||||
|
||||
exitProcs.setProgramResult(1)
|
||||
|
||||
@ -1060,7 +1066,9 @@ template skip* =
|
||||
else:
|
||||
bind checkpoints
|
||||
|
||||
testStatusIMPL = TestStatus.SKIPPED
|
||||
when declared(testStatusIMPL):
|
||||
testStatusIMPL = TestStatus.SKIPPED
|
||||
testStatusObj.status = TestStatus.SKIPPED
|
||||
checkpoints = @[]
|
||||
|
||||
proc runDirect(test: Test) =
|
||||
@ -1124,6 +1132,7 @@ template runtimeTest*(nameParam: string, body: untyped) =
|
||||
when NimMajor>=2:
|
||||
{.pop.}
|
||||
|
||||
testStatusObj.status = TestStatus.OK
|
||||
failingOnExceptions("[setup] "):
|
||||
when declared(testSetupIMPLFlag): testSetupIMPL()
|
||||
defer: failingOnExceptions("[teardown] "):
|
||||
@ -1132,8 +1141,10 @@ template runtimeTest*(nameParam: string, body: untyped) =
|
||||
body
|
||||
|
||||
checkpoints = @[]
|
||||
|
||||
testStatusIMPL
|
||||
if testStatusObj.enabled:
|
||||
testStatusObj.status
|
||||
else:
|
||||
testStatusIMPL
|
||||
|
||||
let
|
||||
localSuiteName =
|
||||
@ -1160,12 +1171,14 @@ template staticTest*(nameParam: string, body: untyped) =
|
||||
echo "[", TestStatus.OK, " ] ", nameParam
|
||||
|
||||
template dualTest*(nameParam: string, body: untyped) =
|
||||
## Similar to `test` but run the test both compuletime and run time, no
|
||||
## Similar to `test` but run the test both compiletime and run time, no
|
||||
## matter the `unittest2Static` flag
|
||||
testStatusObj.enabled = true
|
||||
staticTest nameParam:
|
||||
body
|
||||
runtimeTest nameParam:
|
||||
body
|
||||
testStatusObj.enabled = false
|
||||
|
||||
template test*(nameParam: string, body: untyped) =
|
||||
## Define a single test case identified by `name`.
|
||||
@ -1181,12 +1194,14 @@ template test*(nameParam: string, body: untyped) =
|
||||
## .. code-block::
|
||||
##
|
||||
## [OK] roses are red
|
||||
testStatusObj.enabled = true
|
||||
when nimvm:
|
||||
when unittest2Static:
|
||||
staticTest nameParam:
|
||||
body
|
||||
runtimeTest nameParam:
|
||||
body
|
||||
testStatusObj.enabled = false
|
||||
|
||||
{.pop.} # raises: []
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user