mirror of
https://github.com/status-im/nim-unittest2.git
synced 2025-02-23 15:18:08 +00:00
Fix expect
& nim 1.6 regressions (#24)
This commit is contained in:
parent
0e18d15d3e
commit
883c7a50ad
@ -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
|
||||
|
@ -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())
|
||||
|
Loading…
x
Reference in New Issue
Block a user