2023-06-22 18:01:21 +00:00
|
|
|
import pkg/chronos
|
|
|
|
|
|
|
|
# Allow multiple setups and teardowns in a test suite
|
|
|
|
template asyncmultisetup* =
|
2024-07-18 21:04:33 +00:00
|
|
|
var setups: seq[proc: Future[void].Raising([AsyncExceptionError]) {.gcsafe.}]
|
|
|
|
var teardowns: seq[
|
|
|
|
proc: Future[void].Raising([AsyncExceptionError]) {.gcsafe.}]
|
2023-06-22 18:01:21 +00:00
|
|
|
|
|
|
|
setup:
|
|
|
|
for setup in setups:
|
|
|
|
await setup()
|
|
|
|
|
|
|
|
teardown:
|
|
|
|
for teardown in teardowns:
|
|
|
|
await teardown()
|
|
|
|
|
2023-09-13 14:17:56 +00:00
|
|
|
template setup(setupBody) {.inject, used.} =
|
2024-07-18 21:04:33 +00:00
|
|
|
setups.add(proc {.async: (
|
|
|
|
handleException: true, raises: [AsyncExceptionError]).} = setupBody)
|
2023-06-22 18:01:21 +00:00
|
|
|
|
2023-09-13 14:17:56 +00:00
|
|
|
template teardown(teardownBody) {.inject, used.} =
|
2024-07-18 21:04:33 +00:00
|
|
|
teardowns.insert(proc {.async: (
|
|
|
|
handleException: true, raises: [AsyncExceptionError]).} = teardownBody)
|
2023-06-22 18:01:21 +00:00
|
|
|
|
|
|
|
template multisetup* =
|
|
|
|
var setups: seq[proc() {.gcsafe.}]
|
|
|
|
var teardowns: seq[proc() {.gcsafe.}]
|
|
|
|
|
|
|
|
setup:
|
|
|
|
for setup in setups:
|
|
|
|
setup()
|
|
|
|
|
|
|
|
teardown:
|
|
|
|
for teardown in teardowns:
|
|
|
|
teardown()
|
|
|
|
|
2023-09-13 14:17:56 +00:00
|
|
|
template setup(setupBody) {.inject, used.} =
|
2024-07-18 21:04:33 +00:00
|
|
|
let setupProc = proc = setupBody
|
|
|
|
setups.add(setupProc)
|
2023-06-22 18:01:21 +00:00
|
|
|
|
2023-09-13 14:17:56 +00:00
|
|
|
template teardown(teardownBody) {.inject, used.} =
|
2023-06-22 18:01:21 +00:00
|
|
|
teardowns.insert(proc = teardownBody)
|