Fix crash when unhandled exception is cleared by teardown
This commit is contained in:
parent
32e62b6589
commit
3aaa852b43
|
@ -20,8 +20,10 @@ template suite*(name, body) =
|
|||
|
||||
template teardown(teardownBody) {.used.} =
|
||||
teardown:
|
||||
let exception = getCurrentException()
|
||||
let asyncproc = proc {.async.} = teardownBody
|
||||
waitFor asyncproc()
|
||||
setCurrentException(exception)
|
||||
|
||||
let suiteproc = proc = # Avoids GcUnsafe2 warnings with chronos
|
||||
body
|
||||
|
|
|
@ -2,3 +2,4 @@ import pkg/asynctest
|
|||
import pkg/chronos
|
||||
|
||||
include ../stdlib/testbody
|
||||
include ../stdlib/testfail
|
||||
|
|
|
@ -2,3 +2,4 @@ import std/asyncdispatch
|
|||
import pkg/asynctest
|
||||
|
||||
include ./testbody
|
||||
include ./testfail
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
import std/exitprocs
|
||||
|
||||
template silent(body) =
|
||||
|
||||
let exitcode = getProgramResult()
|
||||
resetOutputFormatters()
|
||||
addOutputFormatter(OutputFormatter())
|
||||
|
||||
body
|
||||
|
||||
resetOutputFormatters()
|
||||
addOutputFormatter(defaultConsoleFormatter())
|
||||
setProgramResult(exitcode)
|
||||
|
||||
suite "reports unhandled exception when teardown handles exceptions too":
|
||||
|
||||
silent:
|
||||
|
||||
proc someAsyncProc {.async.} = discard
|
||||
|
||||
teardown:
|
||||
try:
|
||||
await someAsyncProc()
|
||||
except:
|
||||
discard
|
||||
|
||||
test "should fail, but not crash":
|
||||
raise newException(ValueError, "This exception is expected")
|
|
@ -2,3 +2,4 @@ import pkg/asynctest/unittest2
|
|||
import pkg/chronos
|
||||
|
||||
include ../stdlib/testbody
|
||||
include ../stdlib/testfail
|
||||
|
|
Loading…
Reference in New Issue