commit bb5bc92605331635cb4ffcba19b37dc9a6f1b8ae Author: Mark Spanbroek Date: Mon Jan 11 12:02:40 2021 +0100 Asynchronous testing in Nim diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..1963f8d --- /dev/null +++ b/.editorconfig @@ -0,0 +1,5 @@ +[*] +indent_style = space +insert_final_newline = true +indent_size = 2 +trim_trailing_whitespace = true \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..1648b34 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,15 @@ +name: CI + +on: [push, pull_request] + +jobs: + test: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macOS-latest, windows-latest] + steps: + - uses: actions/checkout@v2 + - uses: iffy/install-nim@v3 + - name: Test + run: nimble test -y diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fedb828 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +* +!*/ +!*.* \ No newline at end of file diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..9ed7760 --- /dev/null +++ b/.tool-versions @@ -0,0 +1 @@ +nim 1.4.2 diff --git a/asynctest.nim b/asynctest.nim new file mode 100644 index 0000000..53dc553 --- /dev/null +++ b/asynctest.nim @@ -0,0 +1,14 @@ +template asynctest*(name, body) = + test name: + let asyncproc = proc {.async.} = body + waitFor asyncproc() + +template asyncsetup*(body) = + setup: + let asyncproc = proc {.async.} = body + waitFor asyncproc() + +template asyncteardown*(body) = + teardown: + let asyncproc = proc {.async.} = body + waitFor asyncproc() diff --git a/asynctest.nimble b/asynctest.nimble new file mode 100644 index 0000000..33ef1ff --- /dev/null +++ b/asynctest.nimble @@ -0,0 +1,6 @@ +version = "0.1.0" +author = "asynctest Authors" +description = "Test asynchronous code" +license = "MIT" + +requires "nim >= 1.2.0 & < 2.0.0" diff --git a/tests/nim.cfg b/tests/nim.cfg new file mode 100644 index 0000000..0f840a1 --- /dev/null +++ b/tests/nim.cfg @@ -0,0 +1 @@ +--path:".." diff --git a/tests/testAsyncTest.nim b/tests/testAsyncTest.nim new file mode 100644 index 0000000..29a16d5 --- /dev/null +++ b/tests/testAsyncTest.nim @@ -0,0 +1,16 @@ +import std/unittest +import std/asyncdispatch +import pkg/asynctest + +suite "async tests": + + proc asyncproc {.async.} = discard + + asyncsetup: # allows await in setup + await asyncproc() + + asyncteardown: # allows await in teardown + await asyncproc() + + asynctest "allows await in tests": + await asyncproc()