mirror of
https://github.com/logos-storage/asynctest.git
synced 2026-01-07 15:33:07 +00:00
add exception handling shim for Chronos V4
This commit is contained in:
parent
048d8e419e
commit
0bcd95b3de
@ -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) =
|
template suite*(name, body) =
|
||||||
|
|
||||||
suite name:
|
suite name:
|
||||||
@ -10,18 +25,18 @@ template suite*(name, body) =
|
|||||||
## Runs after all tests in the suite
|
## Runs after all tests in the suite
|
||||||
template teardownAll(teardownAllBody) {.used.} =
|
template teardownAll(teardownAllBody) {.used.} =
|
||||||
template teardownAllIMPL: untyped {.inject.} =
|
template teardownAllIMPL: untyped {.inject.} =
|
||||||
let a = proc {.async.} = teardownAllBody
|
let a = proc {.async.} = launderExceptions: teardownAllBody
|
||||||
waitFor a()
|
waitFor a()
|
||||||
|
|
||||||
template setup(setupBody) {.used.} =
|
template setup(setupBody) {.used.} =
|
||||||
setup:
|
setup:
|
||||||
let asyncproc = proc {.async.} = setupBody
|
let asyncproc = proc {.async.} = launderExceptions: setupBody
|
||||||
waitFor asyncproc()
|
waitFor asyncproc()
|
||||||
|
|
||||||
template teardown(teardownBody) {.used.} =
|
template teardown(teardownBody) {.used.} =
|
||||||
teardown:
|
teardown:
|
||||||
let exception = getCurrentException()
|
let exception = getCurrentException()
|
||||||
let asyncproc = proc {.async.} = teardownBody
|
let asyncproc = proc {.async.} = launderExceptions: teardownBody
|
||||||
waitFor asyncproc()
|
waitFor asyncproc()
|
||||||
setCurrentException(exception)
|
setCurrentException(exception)
|
||||||
|
|
||||||
@ -35,5 +50,5 @@ template suite*(name, body) =
|
|||||||
|
|
||||||
template test*(name, body) =
|
template test*(name, body) =
|
||||||
test name:
|
test name:
|
||||||
let asyncproc = proc {.async.} = body
|
let asyncproc = proc {.async.} = launderExceptions: body
|
||||||
waitFor asyncproc()
|
waitFor asyncproc()
|
||||||
|
|||||||
@ -3,7 +3,7 @@ author = "Asynctest Authors"
|
|||||||
description = "Asynctest tests for pkg/unittest2 and pkg/chronos"
|
description = "Asynctest tests for pkg/unittest2 and pkg/chronos"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
||||||
requires "unittest2"
|
requires "unittest2 <= 0.0.9"
|
||||||
requires "chronos"
|
requires "chronos"
|
||||||
|
|
||||||
task test, "Runs the test suite":
|
task test, "Runs the test suite":
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user