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:
|
# Also supposed to work outside tests:
|
||||||
check 1 == 1
|
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,7 +1110,10 @@ template runtimeTest*(nameParam: string, body: untyped) =
|
||||||
fail()
|
fail()
|
||||||
|
|
||||||
template failingOnExceptions(prefix: string, code: untyped): untyped =
|
template failingOnExceptions(prefix: string, code: untyped): untyped =
|
||||||
|
when NimMajor>=2:
|
||||||
|
{.push warning[UnnamedBreak]:off.}
|
||||||
try:
|
try:
|
||||||
|
block:
|
||||||
code
|
code
|
||||||
except CatchableError as e:
|
except CatchableError as e:
|
||||||
prefix.fail("error", e)
|
prefix.fail("error", e)
|
||||||
|
@ -1118,6 +1121,8 @@ template runtimeTest*(nameParam: string, body: untyped) =
|
||||||
prefix.fail("defect", e)
|
prefix.fail("defect", e)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
prefix.fail("exception that may cause undefined behavior", e)
|
prefix.fail("exception that may cause undefined behavior", e)
|
||||||
|
when NimMajor>=2:
|
||||||
|
{.pop.}
|
||||||
|
|
||||||
failingOnExceptions("[setup] "):
|
failingOnExceptions("[setup] "):
|
||||||
when declared(testSetupIMPLFlag): testSetupIMPL()
|
when declared(testSetupIMPLFlag): testSetupIMPL()
|
||||||
|
@ -1145,7 +1150,6 @@ template runtimeTest*(nameParam: string, body: untyped) =
|
||||||
else:
|
else:
|
||||||
runDirect(instance)
|
runDirect(instance)
|
||||||
|
|
||||||
|
|
||||||
template staticTest*(nameParam: string, body: untyped) =
|
template staticTest*(nameParam: string, body: untyped) =
|
||||||
## Similar to `test` but runs only at compiletime, no matter the
|
## Similar to `test` but runs only at compiletime, no matter the
|
||||||
## `unittest2Static` flag
|
## `unittest2Static` flag
|
||||||
|
|
Loading…
Reference in New Issue