diff --git a/asyncdispatch2.nimble b/asyncdispatch2.nimble index 361202d4..d1a5fd08 100644 --- a/asyncdispatch2.nimble +++ b/asyncdispatch2.nimble @@ -22,6 +22,10 @@ task test, "Run all tests": exec "nim c -r tests/testtime" exec "nim c -r -d:release tests/testtime" + exec "nim c -r -d:useSysAssert -d:useGcAssert tests/testfut" + exec "nim c -r tests/testfut" + exec "nim c -r -d:release tests/testfut" + exec "nim c -r -d:useSysAssert -d:useGcAssert tests/testdatagram" exec "nim c -r tests/testdatagram" exec "nim c -r -d:release tests/testdatagram" diff --git a/tests/testfut.nim b/tests/testfut.nim new file mode 100644 index 00000000..4936cb20 --- /dev/null +++ b/tests/testfut.nim @@ -0,0 +1,39 @@ +# Asyncdispatch2 Test Suite +# (c) Copyright 2018 +# Status Research & Development GmbH +# +# Licensed under either of +# Apache License, version 2.0, (LICENSE-APACHEv2) +# MIT license (LICENSE-MIT) + +import unittest +import ../asyncdispatch2 + +when defined(vcc): + {.passC: "/Zi /FS".} + +proc testFuture1(): Future[int] {.async.} = + await sleepAsync(100) + +proc testFuture2(): Future[int] {.async.} = + return 1 + +proc testFuture3(): Future[int] {.async.} = + result = await testFuture2() + +proc test1(): bool = + var fut = testFuture1() + poll() + poll() + result = fut.finished + +proc test2(): bool = + var fut = testFuture3() + result = fut.finished + +when isMainModule: + suite "Future[T] behavior test suite": + test "sleepAsync() test": + check test1() == true + test "Immediately completed asynchronous procedure test": + check test2() == true