Fix allow break in test body regression (#38)
* Fix allow break in test body regression * Silence UnnamedBreak warning * Use push/pop pragma to silence UnnamedBreak warning
This commit is contained in:
parent
0fe665e509
commit
e98a1ed79f
|
@ -228,3 +228,13 @@ when defined(testing):
|
|||
# Also supposed to work outside tests:
|
||||
check 1 == 1
|
||||
|
||||
suite "break should works inside test body":
|
||||
var number: int = 0
|
||||
test "step one":
|
||||
number = 2
|
||||
test "step two":
|
||||
if number == 2:
|
||||
break
|
||||
number = 3
|
||||
test "step three":
|
||||
check number == 2
|
||||
|
|
|
@ -1110,14 +1110,19 @@ template runtimeTest*(nameParam: string, body: untyped) =
|
|||
fail()
|
||||
|
||||
template failingOnExceptions(prefix: string, code: untyped): untyped =
|
||||
when NimMajor>=2:
|
||||
{.push warning[UnnamedBreak]:off.}
|
||||
try:
|
||||
code
|
||||
block:
|
||||
code
|
||||
except CatchableError as e:
|
||||
prefix.fail("error", e)
|
||||
except Defect as e: # This may or may not work dependings on --panics
|
||||
prefix.fail("defect", e)
|
||||
except Exception as e:
|
||||
prefix.fail("exception that may cause undefined behavior", e)
|
||||
when NimMajor>=2:
|
||||
{.pop.}
|
||||
|
||||
failingOnExceptions("[setup] "):
|
||||
when declared(testSetupIMPLFlag): testSetupIMPL()
|
||||
|
@ -1145,7 +1150,6 @@ template runtimeTest*(nameParam: string, body: untyped) =
|
|||
else:
|
||||
runDirect(instance)
|
||||
|
||||
|
||||
template staticTest*(nameParam: string, body: untyped) =
|
||||
## Similar to `test` but runs only at compiletime, no matter the
|
||||
## `unittest2Static` flag
|
||||
|
|
Loading…
Reference in New Issue