mirror of
https://github.com/logos-storage/asynctest.git
synced 2026-01-02 13:03:07 +00:00
feat: add support for suite before and after
`before` executes async code before all tests in the suite. `after` executes async code after all tests in the suite.
This commit is contained in:
parent
d2089a6182
commit
33946768c1
12
Readme.md
12
Readme.md
@ -33,12 +33,20 @@ proc someAsyncProc {.async.} =
|
||||
|
||||
suite "test async proc":
|
||||
|
||||
setupAll:
|
||||
# invoke await in the suite setup:
|
||||
await someAsyncProc()
|
||||
|
||||
teardownAll:
|
||||
# invoke await in the suite teardown:
|
||||
await someAsyncProc()
|
||||
|
||||
setup:
|
||||
# invoke await in the test setup:
|
||||
# invoke await in each test setup:
|
||||
await someAsyncProc()
|
||||
|
||||
teardown:
|
||||
# invoke await in the test teardown:
|
||||
# invoke await in each test teardown:
|
||||
await someAsyncProc()
|
||||
|
||||
test "async test":
|
||||
|
||||
@ -1,6 +1,18 @@
|
||||
template suite*(name, body) =
|
||||
|
||||
suite name:
|
||||
|
||||
# Runs before all tests in the suite
|
||||
template setupAll(setupAllBody) {.used.} =
|
||||
let b = proc {.async.} = setupAllBody
|
||||
waitFor b()
|
||||
|
||||
# Runs after all tests in the suite
|
||||
template teardownAll(teardownAllBody) {.used.} =
|
||||
template teardownAllIMPL: untyped {.inject.} =
|
||||
let a = proc {.async.} = teardownAllBody
|
||||
waitFor a()
|
||||
|
||||
template setup(setupBody) {.used.} =
|
||||
setup:
|
||||
let asyncproc = proc {.async.} = setupBody
|
||||
@ -11,7 +23,12 @@ template suite*(name, body) =
|
||||
let asyncproc = proc {.async.} = teardownBody
|
||||
waitFor asyncproc()
|
||||
|
||||
let suiteproc = proc = body # Avoids GcUnsafe2 warnings with chronos
|
||||
let suiteproc = proc = # Avoids GcUnsafe2 warnings with chronos
|
||||
body
|
||||
|
||||
when declared(teardownAllIMPL):
|
||||
teardownAllIMPL()
|
||||
|
||||
suiteproc()
|
||||
|
||||
template test*(name, body) =
|
||||
|
||||
@ -15,3 +15,17 @@ suite "test async proc":
|
||||
test "async test":
|
||||
# invoke await in tests:
|
||||
await someAsyncProc()
|
||||
|
||||
suite "test async setupAll and teardownAll, allow multiple suites":
|
||||
|
||||
setupAll:
|
||||
# invoke await in the test setup:
|
||||
await someAsyncProc()
|
||||
|
||||
teardownAll:
|
||||
# invoke await in the test teardown:
|
||||
await someAsyncProc()
|
||||
|
||||
test "async test":
|
||||
# invoke await in tests:
|
||||
await someAsyncProc()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user