From db3d1e044184c90bca347420a1fd910b01de5ccd Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Thu, 21 Dec 2023 14:42:54 +0100 Subject: [PATCH] Update Readme with new imports --- Readme.md | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/Readme.md b/Readme.md index fdf743c..91fdf5b 100644 --- a/Readme.md +++ b/Readme.md @@ -17,16 +17,29 @@ requires "asynctest >= 0.4.3 & < 0.5.0" Usage ----- -Simply replace `import unittest` with `import asynctest`, and you can await +Replace `import unittest` with one of the following imports, and you can await asynchronous calls in tests, setup and teardown. +When you use Nim's standard library only ([asyncdispatch][4] and [unittest][1]): +```nim +import asynctest/asyncdispatch/unittest +``` + +When you use [chronos][5] or [unittest2][3], pick the import that matches your +choices: + +```nim +import asynctest/asyncdispatch/unittest2 # standard async and unittest2 +import asynctest/chronos/unittest # chronos and standard unittest +import asynctest/chronos/unittest2 # chronos and unittest2 +``` + Example ------- ```nim -import asynctest -import asyncdispatch # alternatively: import chronos +import asynctest/asyncdispatch/unittest proc someAsyncProc {.async.} = # perform some async operations using await @@ -47,17 +60,6 @@ suite "test async proc": ``` -setupAll and teardownAll ------------------------- - -The `setup` and `teardown` code runs before and after every test, just like the -standard [unittest][1] module. In addition we provide `setupAll` and -`teardownAll`. The `setupAll` code runs once before all tests in the suite, and -the `teardownAll` runs once after all tests in the suite. Use these only as a -last resort when setting up the test environment is very costly. Be careful that -the tests do not modify the environment that you set up, lest you introduce -dependencies between tests. - check eventually ---------------- @@ -78,12 +80,20 @@ check eventually x == 42 await future ``` -Unittest2 ---------- +setupAll and teardownAll +------------------------ + +The `setup` and `teardown` code runs before and after every test, just like the +standard [unittest][1] module. In addition we provide `setupAll` and +`teardownAll`. The `setupAll` code runs once before all tests in the suite, and +the `teardownAll` runs once after all tests in the suite. Use these only as a +last resort when setting up the test environment is very costly. Be careful that +the tests do not modify the environment that you set up, lest you introduce +dependencies between tests. -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 +[4]: https://nim-lang.org/docs/asyncdispatch.html +[5]: https://github.com/status-im/nim-chronos/