mirror of
https://github.com/logos-storage/asynctest.git
synced 2026-01-04 05:53:10 +00:00
Fix crash when unhandled exception is cleared by teardown
This commit is contained in:
parent
6ecb089c1f
commit
f9cb40f88b
@ -20,8 +20,10 @@ template suite*(name, body) =
|
|||||||
|
|
||||||
template teardown(teardownBody) {.used.} =
|
template teardown(teardownBody) {.used.} =
|
||||||
teardown:
|
teardown:
|
||||||
|
let exception = getCurrentException()
|
||||||
let asyncproc = proc {.async.} = teardownBody
|
let asyncproc = proc {.async.} = teardownBody
|
||||||
waitFor asyncproc()
|
waitFor asyncproc()
|
||||||
|
setCurrentException(exception)
|
||||||
|
|
||||||
let suiteproc = proc = # Avoids GcUnsafe2 warnings with chronos
|
let suiteproc = proc = # Avoids GcUnsafe2 warnings with chronos
|
||||||
body
|
body
|
||||||
|
|||||||
@ -2,3 +2,4 @@ import pkg/asynctest
|
|||||||
import pkg/chronos
|
import pkg/chronos
|
||||||
|
|
||||||
include ../stdlib/testbody
|
include ../stdlib/testbody
|
||||||
|
include ../stdlib/testfail
|
||||||
|
|||||||
@ -2,3 +2,4 @@ import std/asyncdispatch
|
|||||||
import pkg/asynctest
|
import pkg/asynctest
|
||||||
|
|
||||||
include ./testbody
|
include ./testbody
|
||||||
|
include ./testfail
|
||||||
|
|||||||
28
testmodules/stdlib/testfail.nim
Normal file
28
testmodules/stdlib/testfail.nim
Normal file
@ -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
|
import pkg/chronos
|
||||||
|
|
||||||
include ../stdlib/testbody
|
include ../stdlib/testbody
|
||||||
|
include ../stdlib/testfail
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user