diff --git a/.github/workflows/mops-test.yml b/.github/workflows/mops-test.yml index 92d6783..6db078f 100644 --- a/.github/workflows/mops-test.yml +++ b/.github/workflows/mops-test.yml @@ -12,16 +12,11 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: - node-version: 18 - - - name: install moc - run: npx mocv use latest - - - name: install mops - run: npm i ic-mops -g + node-version: 20 + - uses: ZenVoich/setup-mops@v1 - name: install mops packages run: mops install diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d3f851..c8737ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +## 2.0.0 + +- Requires `moc` version `0.11.0` or higher. +- Added `testsys` function to run tests with `system` capability. (by @skilesare) + +Example: +```motoko +testsys("test", func() { + myFunc(); +}); +``` + ## 1.2.0 - Fixed test run in `wasi` mode diff --git a/README.md b/README.md index 582fbf8..291766b 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,17 @@ await suite("my async test suite", func() : async () { }); ``` +## Tests with `` capability +Use `testsys` to run tests with `system` capability. + +```motoko +import {testsys} "mo:test"; + +testsys("test", func() { + myFunc(); +}); +``` + # Expect ```motoko diff --git a/mops.toml b/mops.toml index 7661beb..bd086d7 100644 --- a/mops.toml +++ b/mops.toml @@ -7,4 +7,11 @@ keywords = [ "test", "testing", "unit", "suite", "expect", "matchers", "mops" ] license = "MIT" [dependencies] -base = "0.10.2" \ No newline at end of file +base = "0.11.1" + +[toolchain] +moc = "0.11.1" +wasmtime = "19.0.0" + +[requirements] +moc = "0.11.0" \ No newline at end of file diff --git a/src/async.mo b/src/async.mo index f528ffd..15d28a7 100644 --- a/src/async.mo +++ b/src/async.mo @@ -9,11 +9,17 @@ module { Debug.print("mops:1:end " # name); }; + public func testsys(name : Text, fn : () -> async ()) : async () { + Debug.print("mops:1:start " # name); + await fn(); + Debug.print("mops:1:end " # name); + }; + public func suite(name : Text, fn : () -> async ()) : async () { await test(name, fn); }; - public func skip(name : Text, fn : () -> async ()) : async () { + public func skip(name : Text, _fn : () -> async ()) : async () { Debug.print("mops:1:skip " # name); }; diff --git a/src/lib.mo b/src/lib.mo index 3968fa6..4f7cafa 100644 --- a/src/lib.mo +++ b/src/lib.mo @@ -18,7 +18,7 @@ module { test(name, fn); }; - public func skip(name : Text, fn : () -> ()) { + public func skip(name : Text, _fn : () -> ()) { Debug.print("mops:1:skip " # name); }; diff --git a/test/async.test.mo b/test/async.test.mo index e2de5eb..d650aad 100644 --- a/test/async.test.mo +++ b/test/async.test.mo @@ -1,16 +1,16 @@ import Debug "mo:base/Debug"; import {suite; test} "../src/async"; -await suite("async suite", func(): async () { - await test("async test", func(): async () { +await suite("async suite", func() : async () { + await test("async test", func() : async () { assert true; }); - await test("async test", func(): async () { + await test("async test", func() : async () { assert true; }); }); -await test("sole async test", func(): async () { +await test("sole async test", func() : async () { assert true; }); \ No newline at end of file diff --git a/test/system-async.test.mo b/test/system-async.test.mo new file mode 100644 index 0000000..e6db72b --- /dev/null +++ b/test/system-async.test.mo @@ -0,0 +1,18 @@ +import Debug "mo:base/Debug"; +import {test; testsys} "../src/async"; + +func sys() {}; + +await test("test", func() : async () { + assert true; +}); + +testsys("test 1", func() : async() { + await testsys("test 1.1", func() : async() { + sys(); + }); + + await testsys("test 1.2", func() : async() { + sys(); + }); +}); \ No newline at end of file diff --git a/test/system.test.mo b/test/system.test.mo new file mode 100644 index 0000000..d8dd095 --- /dev/null +++ b/test/system.test.mo @@ -0,0 +1,18 @@ +import Debug "mo:base/Debug"; +import {test; testsys} "../src"; + +func sys() {}; + +test("test", func() { + assert true; +}); + +testsys("test 1", func() { + testsys("test 1.1", func() { + sys(); + }); + + testsys("test 1.2", func() { + sys(); + }); +}); \ No newline at end of file