Asynchronous testing in Nim

This commit is contained in:
Mark Spanbroek 2021-01-11 12:02:40 +01:00
commit bb5bc92605
8 changed files with 61 additions and 0 deletions

5
.editorconfig Normal file
View File

@ -0,0 +1,5 @@
[*]
indent_style = space
insert_final_newline = true
indent_size = 2
trim_trailing_whitespace = true

15
.github/workflows/test.yml vendored Normal file
View File

@ -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

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*
!*/
!*.*

1
.tool-versions Normal file
View File

@ -0,0 +1 @@
nim 1.4.2

14
asynctest.nim Normal file
View File

@ -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()

6
asynctest.nimble Normal file
View File

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

1
tests/nim.cfg Normal file
View File

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

16
tests/testAsyncTest.nim Normal file
View File

@ -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()