mirror of
https://github.com/logos-storage/asynctest.git
synced 2026-01-03 21:43:11 +00:00
Add support for unittest2
This commit is contained in:
parent
a7f3ae9428
commit
2e00a43236
@ -47,5 +47,12 @@ suite "test async proc":
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Unittest2
|
||||||
|
---------
|
||||||
|
|
||||||
|
The [unittest2][3] package is supported. Make sure that you
|
||||||
|
`import asynctest/unittest2` instead of the normal import.
|
||||||
|
|
||||||
[1]: https://nim-lang.org/docs/unittest.html
|
[1]: https://nim-lang.org/docs/unittest.html
|
||||||
[2]: https://github.com/nim-lang/nimble
|
[2]: https://github.com/nim-lang/nimble
|
||||||
|
[3]: https://github.com/status-im/nim-unittest2
|
||||||
|
|||||||
@ -1,23 +1,3 @@
|
|||||||
import unittest
|
import ./asynctest/unittest
|
||||||
export unittest except suite, test
|
|
||||||
|
|
||||||
template suite*(name, body) =
|
export unittest
|
||||||
suite name:
|
|
||||||
|
|
||||||
template setup(setupBody) {.used.} =
|
|
||||||
setup:
|
|
||||||
let asyncproc = proc {.async.} = setupBody
|
|
||||||
waitFor asyncproc()
|
|
||||||
|
|
||||||
template teardown(teardownBody) {.used.} =
|
|
||||||
teardown:
|
|
||||||
let asyncproc = proc {.async.} = teardownBody
|
|
||||||
waitFor asyncproc()
|
|
||||||
|
|
||||||
let suiteproc = proc = body # Avoids GcUnsafe2 warnings with chronos
|
|
||||||
suiteproc()
|
|
||||||
|
|
||||||
template test*(name, body) =
|
|
||||||
test name:
|
|
||||||
let asyncproc = proc {.async.} = body
|
|
||||||
waitFor asyncproc()
|
|
||||||
|
|||||||
@ -4,3 +4,9 @@ description = "Test asynchronous code"
|
|||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
||||||
requires "nim >= 1.2.0 & < 2.0.0"
|
requires "nim >= 1.2.0 & < 2.0.0"
|
||||||
|
|
||||||
|
task test, "Runs the test suite":
|
||||||
|
for module in ["stdlib", "chronos", "unittest2"]:
|
||||||
|
withDir "testmodules/" & module:
|
||||||
|
exec "nimble install -d -y"
|
||||||
|
exec "nimble test -y"
|
||||||
|
|||||||
20
asynctest/templates.nim
Normal file
20
asynctest/templates.nim
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
template suite*(name, body) =
|
||||||
|
suite name:
|
||||||
|
|
||||||
|
template setup(setupBody) {.used.} =
|
||||||
|
setup:
|
||||||
|
let asyncproc = proc {.async.} = setupBody
|
||||||
|
waitFor asyncproc()
|
||||||
|
|
||||||
|
template teardown(teardownBody) {.used.} =
|
||||||
|
teardown:
|
||||||
|
let asyncproc = proc {.async.} = teardownBody
|
||||||
|
waitFor asyncproc()
|
||||||
|
|
||||||
|
let suiteproc = proc = body # Avoids GcUnsafe2 warnings with chronos
|
||||||
|
suiteproc()
|
||||||
|
|
||||||
|
template test*(name, body) =
|
||||||
|
test name:
|
||||||
|
let asyncproc = proc {.async.} = body
|
||||||
|
waitFor asyncproc()
|
||||||
4
asynctest/unittest.nim
Normal file
4
asynctest/unittest.nim
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import std/unittest
|
||||||
|
export unittest except suite, test
|
||||||
|
|
||||||
|
include ./templates
|
||||||
4
asynctest/unittest2.nim
Normal file
4
asynctest/unittest2.nim
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import pkg/unittest2
|
||||||
|
export unittest2 except suite, test
|
||||||
|
|
||||||
|
include ./templates
|
||||||
1
testmodules/chronos/nim.cfg
Normal file
1
testmodules/chronos/nim.cfg
Normal file
@ -0,0 +1 @@
|
|||||||
|
--path:"../.."
|
||||||
0
testmodules/chronos/nimbledeps/.keep
Normal file
0
testmodules/chronos/nimbledeps/.keep
Normal file
4
testmodules/chronos/test.nim
Normal file
4
testmodules/chronos/test.nim
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import pkg/asynctest
|
||||||
|
import pkg/chronos
|
||||||
|
|
||||||
|
include ../stdlib/testbody
|
||||||
9
testmodules/chronos/test.nimble
Normal file
9
testmodules/chronos/test.nimble
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
version = "0.1.0"
|
||||||
|
author = "Asynctest Authors"
|
||||||
|
description = "Asynctest tests for std/unittest and pkg/chronos"
|
||||||
|
license = "MIT"
|
||||||
|
|
||||||
|
requires "chronos"
|
||||||
|
|
||||||
|
task test, "Runs the test suite":
|
||||||
|
exec "nim c -f -r test.nim"
|
||||||
1
testmodules/stdlib/nim.cfg
Normal file
1
testmodules/stdlib/nim.cfg
Normal file
@ -0,0 +1 @@
|
|||||||
|
--path:"../.."
|
||||||
0
testmodules/stdlib/nimbledeps/.keep
Normal file
0
testmodules/stdlib/nimbledeps/.keep
Normal file
4
testmodules/stdlib/test.nim
Normal file
4
testmodules/stdlib/test.nim
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import std/asyncdispatch
|
||||||
|
import pkg/asynctest
|
||||||
|
|
||||||
|
include ./testbody
|
||||||
7
testmodules/stdlib/test.nimble
Normal file
7
testmodules/stdlib/test.nimble
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
version = "0.1.0"
|
||||||
|
author = "Asynctest Authors"
|
||||||
|
description = "Asynctest tests for std/unittest and std/asyncdispatch"
|
||||||
|
license = "MIT"
|
||||||
|
|
||||||
|
task test, "Runs the test suite":
|
||||||
|
exec "nim c -f -r test.nim"
|
||||||
@ -1,6 +1,3 @@
|
|||||||
import std/asyncdispatch
|
|
||||||
import pkg/asynctest
|
|
||||||
|
|
||||||
proc someAsyncProc {.async.} =
|
proc someAsyncProc {.async.} =
|
||||||
# perform some async operations using await
|
# perform some async operations using await
|
||||||
discard
|
discard
|
||||||
1
testmodules/unittest2/nim.cfg
Normal file
1
testmodules/unittest2/nim.cfg
Normal file
@ -0,0 +1 @@
|
|||||||
|
--path:"../.."
|
||||||
4
testmodules/unittest2/test.nim
Normal file
4
testmodules/unittest2/test.nim
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import pkg/asynctest/unittest2
|
||||||
|
import pkg/chronos
|
||||||
|
|
||||||
|
include ../stdlib/testbody
|
||||||
10
testmodules/unittest2/test.nimble
Normal file
10
testmodules/unittest2/test.nimble
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
version = "0.1.0"
|
||||||
|
author = "Asynctest Authors"
|
||||||
|
description = "Asynctest tests for pkg/unittest2 and pkg/chronos"
|
||||||
|
license = "MIT"
|
||||||
|
|
||||||
|
requires "unittest2"
|
||||||
|
requires "chronos"
|
||||||
|
|
||||||
|
task test, "Runs the test suite":
|
||||||
|
exec "nim c -f -r test.nim"
|
||||||
@ -1 +0,0 @@
|
|||||||
--path:".."
|
|
||||||
Loading…
x
Reference in New Issue
Block a user