Add support for unittest2

This commit is contained in:
Mark Spanbroek 2021-07-07 10:32:50 +02:00
parent a7f3ae9428
commit 2e00a43236
19 changed files with 84 additions and 26 deletions

View File

@ -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
[2]: https://github.com/nim-lang/nimble
[3]: https://github.com/status-im/nim-unittest2

View File

@ -1,23 +1,3 @@
import unittest
export unittest except suite, test
import ./asynctest/unittest
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()
export unittest

View File

@ -4,3 +4,9 @@ description = "Test asynchronous code"
license = "MIT"
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
View 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
View File

@ -0,0 +1,4 @@
import std/unittest
export unittest except suite, test
include ./templates

4
asynctest/unittest2.nim Normal file
View File

@ -0,0 +1,4 @@
import pkg/unittest2
export unittest2 except suite, test
include ./templates

View File

@ -0,0 +1 @@
--path:"../.."

View File

View File

@ -0,0 +1,4 @@
import pkg/asynctest
import pkg/chronos
include ../stdlib/testbody

View 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"

View File

@ -0,0 +1 @@
--path:"../.."

View File

View File

@ -0,0 +1,4 @@
import std/asyncdispatch
import pkg/asynctest
include ./testbody

View 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"

View File

@ -1,6 +1,3 @@
import std/asyncdispatch
import pkg/asynctest
proc someAsyncProc {.async.} =
# perform some async operations using await
discard

View File

@ -0,0 +1 @@
--path:"../.."

View File

@ -0,0 +1,4 @@
import pkg/asynctest/unittest2
import pkg/chronos
include ../stdlib/testbody

View 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"

View File

@ -1 +0,0 @@
--path:".."