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:
andri lim 2024-01-22 18:59:23 +07:00 committed by GitHub
parent 0fe665e509
commit e98a1ed79f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 4 deletions

View File

@ -59,7 +59,7 @@ suite "PR #36":
test "test body":
server = new(string)
server[] = "hello"
#------------------------------------------------------------------------------
# Regular tests
#------------------------------------------------------------------------------
@ -227,4 +227,14 @@ 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

View File

@ -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