nim-dagger/tests/helpers/multisetup.nim
Giuliano Mega 4f56f2af26
Chronos v4 Update (v3 Compat Mode) (#814)
* add changes to use chronos v4 in compat mode

* switch chronos to compat fix branch

* use nimbus-build-system with configurable Nim repo

* add missing imports

* add missing await

* bump compat

* pin nim version in Makefile

* add await instead of asyncSpawn to advertisement queue loop

* bump DHT to v0.5.0

* allow error state of `onBatch` to propagate upwards in test code

* pin Nim compiler commit to avoid fetching stale branch

* make CI build against branch head instead of merge

* fix handling of return values in testslotqueue
2024-07-18 21:04:33 +00:00

43 lines
1.1 KiB
Nim

import pkg/chronos
# Allow multiple setups and teardowns in a test suite
template asyncmultisetup* =
var setups: seq[proc: Future[void].Raising([AsyncExceptionError]) {.gcsafe.}]
var teardowns: seq[
proc: Future[void].Raising([AsyncExceptionError]) {.gcsafe.}]
setup:
for setup in setups:
await setup()
teardown:
for teardown in teardowns:
await teardown()
template setup(setupBody) {.inject, used.} =
setups.add(proc {.async: (
handleException: true, raises: [AsyncExceptionError]).} = setupBody)
template teardown(teardownBody) {.inject, used.} =
teardowns.insert(proc {.async: (
handleException: true, raises: [AsyncExceptionError]).} = teardownBody)
template multisetup* =
var setups: seq[proc() {.gcsafe.}]
var teardowns: seq[proc() {.gcsafe.}]
setup:
for setup in setups:
setup()
teardown:
for teardown in teardowns:
teardown()
template setup(setupBody) {.inject, used.} =
let setupProc = proc = setupBody
setups.add(setupProc)
template teardown(teardownBody) {.inject, used.} =
teardowns.insert(proc = teardownBody)