add exception handling shim for Chronos V4
This commit is contained in:
parent
048d8e419e
commit
50dfe3aab1
|
@ -1,3 +1,18 @@
|
|||
template launderExceptions(body: typed) =
|
||||
## Chronos V4 requires that all procs which raise Exception annotate it
|
||||
## with {.async: (raises: [Exception]).}, but this construct does not
|
||||
## exist in asyncdispatch. We therefore launder all real instances of
|
||||
## Exception into CatchableError and make Chronos happy while not losing
|
||||
## context information for the remainder of the exception types.
|
||||
try:
|
||||
body
|
||||
except Defect as ex:
|
||||
raise ex
|
||||
except CatchableError as ex:
|
||||
raise ex
|
||||
except Exception as ex:
|
||||
raise newException(CatchableError, ex.msg, ex)
|
||||
|
||||
template suite*(name, body) =
|
||||
|
||||
suite name:
|
||||
|
@ -10,18 +25,18 @@ template suite*(name, body) =
|
|||
## Runs after all tests in the suite
|
||||
template teardownAll(teardownAllBody) {.used.} =
|
||||
template teardownAllIMPL: untyped {.inject.} =
|
||||
let a = proc {.async.} = teardownAllBody
|
||||
let a = proc {.async.} = launderExceptions: teardownAllBody
|
||||
waitFor a()
|
||||
|
||||
template setup(setupBody) {.used.} =
|
||||
setup:
|
||||
let asyncproc = proc {.async.} = setupBody
|
||||
let asyncproc = proc {.async.} = launderExceptions: setupBody
|
||||
waitFor asyncproc()
|
||||
|
||||
template teardown(teardownBody) {.used.} =
|
||||
teardown:
|
||||
let exception = getCurrentException()
|
||||
let asyncproc = proc {.async.} = teardownBody
|
||||
let asyncproc = proc {.async.} = launderExceptions: teardownBody
|
||||
waitFor asyncproc()
|
||||
setCurrentException(exception)
|
||||
|
||||
|
@ -35,5 +50,5 @@ template suite*(name, body) =
|
|||
|
||||
template test*(name, body) =
|
||||
test name:
|
||||
let asyncproc = proc {.async.} = body
|
||||
let asyncproc = proc {.async.} = launderExceptions: body
|
||||
waitFor asyncproc()
|
||||
|
|
|
@ -3,7 +3,7 @@ author = "Asynctest Authors"
|
|||
description = "Asynctest tests for pkg/unittest2 and pkg/chronos"
|
||||
license = "MIT"
|
||||
|
||||
requires "unittest2"
|
||||
requires "unittest2 <= 0.0.9"
|
||||
requires "chronos"
|
||||
|
||||
task test, "Runs the test suite":
|
||||
|
|
Loading…
Reference in New Issue