mirror of
https://github.com/status-im/nim-unittest2.git
synced 2025-02-23 23:28:07 +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:
|
else:
|
||||||
expect IOError, OSError, ValueError, AssertionError:
|
expect IOError, OSError, ValueError, AssertionError:
|
||||||
defectiveRobot()
|
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
|
var
|
||||||
a = 1
|
a = 1
|
||||||
|
@ -159,7 +159,7 @@ else:
|
|||||||
when (NimMajor, NimMinor) > (1, 2):
|
when (NimMajor, NimMinor) > (1, 2):
|
||||||
from std/exitprocs import nil
|
from std/exitprocs import nil
|
||||||
template addExitProc(p: proc) =
|
template addExitProc(p: proc) =
|
||||||
when (NimMajor, NimMinor) >= (1, 6):
|
when defined(nimHasWarnBareExcept):
|
||||||
{.warning[BareExcept]:off.}
|
{.warning[BareExcept]:off.}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -168,7 +168,7 @@ when (NimMajor, NimMinor) > (1, 2):
|
|||||||
echo "Can't add exit proc", e.msg
|
echo "Can't add exit proc", e.msg
|
||||||
quit(1)
|
quit(1)
|
||||||
|
|
||||||
when (NimMajor, NimMinor) >= (1, 6):
|
when defined(nimHasWarnBareExcept):
|
||||||
{.warning[BareExcept]:on.}
|
{.warning[BareExcept]:on.}
|
||||||
else:
|
else:
|
||||||
template addExitProc(p: proc) =
|
template addExitProc(p: proc) =
|
||||||
@ -556,7 +556,7 @@ method testRunEnded*(formatter: JUnitOutputFormatter) =
|
|||||||
## Completes the report and closes the underlying stream.
|
## Completes the report and closes the underlying stream.
|
||||||
let s = formatter.stream
|
let s = formatter.stream
|
||||||
|
|
||||||
when (NimMajor, NimMinor) >= (1, 6):
|
when defined(nimHasWarnBareExcept):
|
||||||
{.warning[BareExcept]:off.}
|
{.warning[BareExcept]:off.}
|
||||||
try:
|
try:
|
||||||
s.writeLine("<testsuites>")
|
s.writeLine("<testsuites>")
|
||||||
@ -573,7 +573,7 @@ method testRunEnded*(formatter: JUnitOutputFormatter) =
|
|||||||
echo "Cannot write JUnit: ", exc.msg
|
echo "Cannot write JUnit: ", exc.msg
|
||||||
quit 1
|
quit 1
|
||||||
|
|
||||||
when (NimMajor, NimMinor) >= (1, 6):
|
when defined(nimHasWarnBareExcept):
|
||||||
{.warning[BareExcept]:on.}
|
{.warning[BareExcept]:on.}
|
||||||
|
|
||||||
proc glob(matcher, filter: string): bool =
|
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.} =
|
template expectBody(errorTypes, lineInfoLit, body): NimNode {.dirty.} =
|
||||||
try:
|
try:
|
||||||
body
|
try:
|
||||||
checkpoint(lineInfoLit & ": Expect Failed, no exception was thrown.")
|
body
|
||||||
fail()
|
checkpoint(lineInfoLit & ": Expect Failed, no exception was thrown.")
|
||||||
except errorTypes:
|
fail()
|
||||||
discard
|
except errorTypes:
|
||||||
|
discard
|
||||||
except CatchableError as e:
|
except CatchableError as e:
|
||||||
checkpoint(lineInfoLit & ": Expect Failed, unexpected " & $e.name &
|
checkpoint(lineInfoLit & ": Expect Failed, unexpected " & $e.name &
|
||||||
" (" & e.msg & ") was thrown.\n" & e.getStackTrace())
|
" (" & e.msg & ") was thrown.\n" & e.getStackTrace())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user