Fix expect & nim 1.6 regressions (#24)

This commit is contained in:
Tanguy 2023-02-17 15:23:16 +01:00 committed by GitHub
parent 0e18d15d3e
commit 883c7a50ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 9 deletions

View File

@ -62,6 +62,14 @@ test "unittest expect":
else:
expect IOError, OSError, ValueError, AssertionError:
defectiveRobot()
expect CatchableError:
if true: raise CatchableError.newException("Okay")
expect CatchableError, ValueError:
if true: raise CatchableError.newException("Okay")
expect Defect:
if true: raise Defect.newException("Okay")
expect Defect, CatchableError:
if true: raise Defect.newException("Okay")
var
a = 1

View File

@ -159,7 +159,7 @@ else:
when (NimMajor, NimMinor) > (1, 2):
from std/exitprocs import nil
template addExitProc(p: proc) =
when (NimMajor, NimMinor) >= (1, 6):
when defined(nimHasWarnBareExcept):
{.warning[BareExcept]:off.}
try:
@ -168,7 +168,7 @@ when (NimMajor, NimMinor) > (1, 2):
echo "Can't add exit proc", e.msg
quit(1)
when (NimMajor, NimMinor) >= (1, 6):
when defined(nimHasWarnBareExcept):
{.warning[BareExcept]:on.}
else:
template addExitProc(p: proc) =
@ -556,7 +556,7 @@ method testRunEnded*(formatter: JUnitOutputFormatter) =
## Completes the report and closes the underlying stream.
let s = formatter.stream
when (NimMajor, NimMinor) >= (1, 6):
when defined(nimHasWarnBareExcept):
{.warning[BareExcept]:off.}
try:
s.writeLine("<testsuites>")
@ -573,7 +573,7 @@ method testRunEnded*(formatter: JUnitOutputFormatter) =
echo "Cannot write JUnit: ", exc.msg
quit 1
when (NimMajor, NimMinor) >= (1, 6):
when defined(nimHasWarnBareExcept):
{.warning[BareExcept]:on.}
proc glob(matcher, filter: string): bool =
@ -1024,11 +1024,12 @@ macro expect*(exceptions: varargs[typed], body: untyped): untyped =
template expectBody(errorTypes, lineInfoLit, body): NimNode {.dirty.} =
try:
body
checkpoint(lineInfoLit & ": Expect Failed, no exception was thrown.")
fail()
except errorTypes:
discard
try:
body
checkpoint(lineInfoLit & ": Expect Failed, no exception was thrown.")
fail()
except errorTypes:
discard
except CatchableError as e:
checkpoint(lineInfoLit & ": Expect Failed, unexpected " & $e.name &
" (" & e.msg & ") was thrown.\n" & e.getStackTrace())