Skip to content

Commit

Permalink
prepare testsys
Browse files Browse the repository at this point in the history
  • Loading branch information
ZenVoich committed Apr 5, 2024
1 parent 36dcc60 commit fbd57e3
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 16 deletions.
13 changes: 4 additions & 9 deletions .github/workflows/mops-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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<system>("test", func<system>() {
myFunc<system>();
});
```

## 1.2.0

- Fixed test run in `wasi` mode
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ await suite("my async test suite", func() : async () {
});
```

## Tests with `<system>` capability
Use `testsys` to run tests with `system` capability.

```motoko
import {testsys} "mo:test";
testsys<system>("test", func<system>() {
myFunc<system>();
});
```

# Expect

```motoko
Expand Down
9 changes: 8 additions & 1 deletion mops.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,11 @@ keywords = [ "test", "testing", "unit", "suite", "expect", "matchers", "mops" ]
license = "MIT"

[dependencies]
base = "0.10.2"
base = "0.11.1"

[toolchain]
moc = "0.11.1"
wasmtime = "19.0.0"

[requirements]
moc = "0.11.0"
8 changes: 7 additions & 1 deletion src/async.mo
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ module {
Debug.print("mops:1:end " # name);
};

public func testsys<system>(name : Text, fn : <system>() -> async ()) : async () {
Debug.print("mops:1:start " # name);
await fn<system>();
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);
};

Expand Down
2 changes: 1 addition & 1 deletion src/lib.mo
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
8 changes: 4 additions & 4 deletions test/async.test.mo
Original file line number Diff line number Diff line change
@@ -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;
});
18 changes: 18 additions & 0 deletions test/system-async.test.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Debug "mo:base/Debug";
import {test; testsys} "../src/async";

func sys<system>() {};

await test("test", func() : async () {
assert true;
});

testsys<system>("test 1", func<system>() : async() {
await testsys<system>("test 1.1", func<system>() : async() {
sys<system>();
});

await testsys<system>("test 1.2", func<system>() : async() {
sys<system>();
});
});
18 changes: 18 additions & 0 deletions test/system.test.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Debug "mo:base/Debug";
import {test; testsys} "../src";

func sys<system>() {};

test("test", func() {
assert true;
});

testsys<system>("test 1", func<system>() {
testsys<system>("test 1.1", func<system>() {
sys<system>();
});

testsys<system>("test 1.2", func<system>() {
sys<system>();
});
});

0 comments on commit fbd57e3

Please sign in to comment.