Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions .github/workflows/mops-test.yml

This file was deleted.

33 changes: 33 additions & 0 deletions .github/workflows/pull_request_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: App build
on:
pull_request:
types: [synchronize, opened, reopened, ready_for_review, unlabeled]

env:
dfx_version: 0.30.1

jobs:
build:
runs-on: ubuntu-22.04

steps:
- name: Checkout repository
uses: actions/checkout@v6
- uses: caffeinelabs/setup-mops@v1

- name: Install dfx
uses: dfinity/setup-dfx@main
with:
dfx-version: ${{ env.dfx_version }}

- name: Confirm dfx version
run: dfx --version

- name: Make sure moc is installed
run: mops toolchain bin moc || mops toolchain use moc latest

- name: Show mops version
run: mops -v

- name: Run mops test
run: mops test
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Mops-test changelog

## Next

- Migrate from base to core 2.0.0

## 2.1.1

- Increase `expect.array` stringify limit from 100 to 20_000 chars
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[![mops](https://oknww-riaaa-aaaam-qaf6a-cai.raw.ic0.app/badge/mops/test)](https://mops.one/test)
[![documentation](https://oknww-riaaa-aaaam-qaf6a-cai.raw.ic0.app/badge/documentation/test)](https://mops.one/test/docs)

# Motoko Testing
Easy way to write tests in Motoko and run them with [`mops test`](https://docs.mops.one/cli/mops-test).

Expand Down Expand Up @@ -108,7 +111,7 @@ To run replica tests, your test file should look like this:
```motoko
...

actor {
persistent actor {
public func runTests() : async () {
// your tests here
};
Expand All @@ -120,7 +123,7 @@ Example:
import {test} "mo:test/async";
import MyCanister "../my-canister";

actor {
persistent actor {
// add cycles to deploy your canister
ExperimentalCycles.add<system>(1_000_000_000_000);

Expand All @@ -136,7 +139,7 @@ actor {
};
```

Make sure your actor doesn't have a name `actor {`.
Make sure your actor doesn't have a name, only `persistent actor {`.

Make sure your actor has `runTests` method.

Expand Down
10 changes: 5 additions & 5 deletions mops.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
name = "test"
version = "2.1.1"
description = "Motoko testing library to run tests with mops"
repository = "https://github.com/dfinity/mops-test"
repository = "https://github.com/caffeinelabs/mops-test"
keywords = [ "test", "testing", "unit", "suite", "expect", "matchers", "mops" ]
license = "MIT"

[dependencies]
base = "0.14.5"
core = "2.0.0"

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

[requirements]
moc = "0.11.0"
moc = "1.0.0"
2 changes: 1 addition & 1 deletion src/async.mo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Debug "mo:base/Debug";
import Debug "mo:core/Debug";
import {expect = _expect; fail = _fail} "./expect";
import {expectAsync = _expectAsync} "./expect/async";
import {formatTestName} "./utils";
Expand Down
25 changes: 15 additions & 10 deletions src/expect/expect-array.mo
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Array "mo:base/Array";
import Option "mo:base/Option";
import Array "mo:core/Array";
import {fail} "./utils";

module {
Expand All @@ -26,28 +25,34 @@ module {
};

public func equal(other : [T]) {
if (not Array.equal<T>(arr, other, itemEqual)) {
if (not arr.equal(other, itemEqual)) {
fail(_arrayToText(arr, STRING_LIMIT), "", _arrayToText(other, STRING_LIMIT));
};
};

public func notEqual(other : [T]) {
if (Array.equal<T>(arr, other, itemEqual)) {
if (arr.equal(other, itemEqual)) {
fail(_arrayToText(arr, STRING_LIMIT), "", _arrayToText(other, STRING_LIMIT));
};
};

public func contains(a : T) {
let has = Array.find<T>(arr, func b = itemEqual(a, b));
if (Option.isNull(has)) {
fail(_arrayToText(arr, STRING_LIMIT), "to contain element", itemToText(a));
let has = arr.find(func b = itemEqual(a, b));
switch (has) {
case (null) {
fail(_arrayToText(arr, STRING_LIMIT), "to contain element", itemToText(a));
};
case (_) {};
};
};

public func notContains(a : T) {
let has = Array.find<T>(arr, func b = itemEqual(a, b));
if (Option.isSome(has)) {
fail(_arrayToText(arr, STRING_LIMIT), "to not contain element", itemToText(a));
let has = arr.find(func b = itemEqual(a, b));
switch (has) {
case (null) {};
case (_) {
fail(_arrayToText(arr, STRING_LIMIT), "to not contain element", itemToText(a));
};
};
};

Expand Down
16 changes: 8 additions & 8 deletions src/expect/expect-blob.mo
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import Blob "mo:base/Blob";
import Blob "mo:core/Blob";
import {bindCompare; fail} "./utils";

module {
public class ExpectBlob<T>(blob : Blob) {
public class ExpectBlob(blob : Blob) {
func show(v : Blob) : Text = "blob \"" # debug_show(v) # "\"";

public let equal = bindCompare<Blob>(blob, Blob.equal, show, "");
public let notEqual = bindCompare<Blob>(blob, Blob.notEqual, show, "!=");
public let less = bindCompare<Blob>(blob, Blob.less, show, "<");
public let lessOrEqual = bindCompare<Blob>(blob, Blob.lessOrEqual, show, "<=");
public let greater = bindCompare<Blob>(blob, Blob.greater, show, ">");
public let greaterOrEqual = bindCompare<Blob>(blob, Blob.greaterOrEqual, show, ">=");
public let equal = bindCompare(blob, Blob.equal, show, "");
public let notEqual = bindCompare(blob, Blob.notEqual, show, "!=");
public let less = bindCompare(blob, Blob.less, show, "<");
public let lessOrEqual = bindCompare(blob, Blob.lessOrEqual, show, "<=");
public let greater = bindCompare(blob, Blob.greater, show, ">");
public let greaterOrEqual = bindCompare(blob, Blob.greaterOrEqual, show, ">=");

public func size(n : Nat) {
if (blob.size() != n) {
Expand Down
10 changes: 5 additions & 5 deletions src/expect/expect-bool.mo
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import Bool "mo:base/Bool";
import Bool_ "mo:core/Bool";
import {fail} "./utils";

module {
public class ExpectBool(a : Bool) {
public func isTrue() {
if (a != true) {
fail(Bool.toText(a), "", Bool.toText(true));
fail(a.toText(), "", true.toText());
};
};
public func isFalse() {
if (a != false) {
fail(Bool.toText(a), "", Bool.toText(false));
fail(a.toText(), "", false.toText());
};
};
public func equal(b : Bool) {
if (a != b) {
fail(Bool.toText(a), "", Bool.toText(b));
fail(a.toText(), "", b.toText());
};
};
public func notEqual(b : Bool) {
if (a == b) {
fail(Bool.toText(a), "to be !=", Bool.toText(b));
fail(a.toText(), "to be !=", b.toText());
};
};
};
Expand Down
6 changes: 3 additions & 3 deletions src/expect/expect-call.mo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Debug "mo:base/Debug";
import Error "mo:base/Error";
import Error "mo:core/Error";
import Runtime "mo:core/Runtime";

module {
public class ExpectCall(fn : () -> async ()) {
Expand All @@ -12,7 +12,7 @@ module {
return;
};
};
Debug.trap("expected to throw error");
Runtime.trap("expected to throw error");
};

// unable to catch
Expand Down
14 changes: 7 additions & 7 deletions src/expect/expect-char.mo
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import Char "mo:base/Char";
import Char "mo:core/Char";
import {bindCompare} "./utils";

module {
public class ExpectChar(val : Char) {
func show(c : Char) : Text = "'" # Char.toText(c) # "'";

public let equal = bindCompare<Char>(val, Char.equal, show, "");
public let notEqual = bindCompare<Char>(val, Char.notEqual, show, "!=");
public let less = bindCompare<Char>(val, Char.less, show, "<");
public let lessOrEqual = bindCompare<Char>(val, Char.lessOrEqual, show, "<=");
public let greater = bindCompare<Char>(val, Char.greater, show, ">");
public let greaterOrEqual = bindCompare<Char>(val, Char.greaterOrEqual, show, ">=");
public let equal = bindCompare(val, Char.equal, show, "");
public let notEqual = bindCompare(val, Char.notEqual, show, "!=");
public let less = bindCompare(val, Char.less, show, "<");
public let lessOrEqual = bindCompare(val, Char.lessOrEqual, show, "<=");
public let greater = bindCompare(val, Char.greater, show, ">");
public let greaterOrEqual = bindCompare(val, Char.greaterOrEqual, show, ">=");
};
};
14 changes: 7 additions & 7 deletions src/expect/expect-int.mo
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Int "mo:base/Int";
import Int "mo:core/Int";
import {bindCompare} "./utils";

module {
public class ExpectInt(val : Int) {
public let equal = bindCompare<Int>(val, Int.equal, Int.toText, "");
public let notEqual = bindCompare<Int>(val, Int.notEqual, Int.toText, "!=");
public let less = bindCompare<Int>(val, Int.less, Int.toText, "<");
public let lessOrEqual = bindCompare<Int>(val, Int.lessOrEqual, Int.toText, "<=");
public let greater = bindCompare<Int>(val, Int.greater, Int.toText, ">");
public let greaterOrEqual = bindCompare<Int>(val, Int.greaterOrEqual, Int.toText, ">=");
public let equal = bindCompare(val, Int.equal, Int.toText, "");
public let notEqual = bindCompare(val, Int.notEqual, Int.toText, "!=");
public let less = bindCompare(val, Int.less, Int.toText, "<");
public let lessOrEqual = bindCompare(val, Int.lessOrEqual, Int.toText, "<=");
public let greater = bindCompare(val, Int.greater, Int.toText, ">");
public let greaterOrEqual = bindCompare(val, Int.greaterOrEqual, Int.toText, ">=");
};
};
14 changes: 7 additions & 7 deletions src/expect/expect-int16.mo
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Int16 "mo:base/Int16";
import Int16 "mo:core/Int16";
import {bindCompare} "./utils";

module {
public class ExpectInt16(val : Int16) {
public let equal = bindCompare<Int16>(val, Int16.equal, Int16.toText, "");
public let notEqual = bindCompare<Int16>(val, Int16.notEqual, Int16.toText, "!=");
public let less = bindCompare<Int16>(val, Int16.less, Int16.toText, "<");
public let lessOrEqual = bindCompare<Int16>(val, Int16.lessOrEqual, Int16.toText, "<=");
public let greater = bindCompare<Int16>(val, Int16.greater, Int16.toText, ">");
public let greaterOrEqual = bindCompare<Int16>(val, Int16.greaterOrEqual, Int16.toText, ">=");
public let equal = bindCompare(val, Int16.equal, Int16.toText, "");
public let notEqual = bindCompare(val, Int16.notEqual, Int16.toText, "!=");
public let less = bindCompare(val, Int16.less, Int16.toText, "<");
public let lessOrEqual = bindCompare(val, Int16.lessOrEqual, Int16.toText, "<=");
public let greater = bindCompare(val, Int16.greater, Int16.toText, ">");
public let greaterOrEqual = bindCompare(val, Int16.greaterOrEqual, Int16.toText, ">=");
};
};
14 changes: 7 additions & 7 deletions src/expect/expect-int32.mo
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Int32 "mo:base/Int32";
import Int32 "mo:core/Int32";
import {bindCompare} "./utils";

module {
public class ExpectInt32(val : Int32) {
public let equal = bindCompare<Int32>(val, Int32.equal, Int32.toText, "");
public let notEqual = bindCompare<Int32>(val, Int32.notEqual, Int32.toText, "!=");
public let less = bindCompare<Int32>(val, Int32.less, Int32.toText, "<");
public let lessOrEqual = bindCompare<Int32>(val, Int32.lessOrEqual, Int32.toText, "<=");
public let greater = bindCompare<Int32>(val, Int32.greater, Int32.toText, ">");
public let greaterOrEqual = bindCompare<Int32>(val, Int32.greaterOrEqual, Int32.toText, ">=");
public let equal = bindCompare(val, Int32.equal, Int32.toText, "");
public let notEqual = bindCompare(val, Int32.notEqual, Int32.toText, "!=");
public let less = bindCompare(val, Int32.less, Int32.toText, "<");
public let lessOrEqual = bindCompare(val, Int32.lessOrEqual, Int32.toText, "<=");
public let greater = bindCompare(val, Int32.greater, Int32.toText, ">");
public let greaterOrEqual = bindCompare(val, Int32.greaterOrEqual, Int32.toText, ">=");
};
};
14 changes: 7 additions & 7 deletions src/expect/expect-int64.mo
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Int64 "mo:base/Int64";
import Int64 "mo:core/Int64";
import {bindCompare} "./utils";

module {
public class ExpectInt64(val : Int64) {
public let equal = bindCompare<Int64>(val, Int64.equal, Int64.toText, "");
public let notEqual = bindCompare<Int64>(val, Int64.notEqual, Int64.toText, "!=");
public let less = bindCompare<Int64>(val, Int64.less, Int64.toText, "<");
public let lessOrEqual = bindCompare<Int64>(val, Int64.lessOrEqual, Int64.toText, "<=");
public let greater = bindCompare<Int64>(val, Int64.greater, Int64.toText, ">");
public let greaterOrEqual = bindCompare<Int64>(val, Int64.greaterOrEqual, Int64.toText, ">=");
public let equal = bindCompare(val, Int64.equal, Int64.toText, "");
public let notEqual = bindCompare(val, Int64.notEqual, Int64.toText, "!=");
public let less = bindCompare(val, Int64.less, Int64.toText, "<");
public let lessOrEqual = bindCompare(val, Int64.lessOrEqual, Int64.toText, "<=");
public let greater = bindCompare(val, Int64.greater, Int64.toText, ">");
public let greaterOrEqual = bindCompare(val, Int64.greaterOrEqual, Int64.toText, ">=");
};
};
14 changes: 7 additions & 7 deletions src/expect/expect-int8.mo
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Int8 "mo:base/Int8";
import Int8 "mo:core/Int8";
import {bindCompare} "./utils";

module {
public class ExpectInt8(val : Int8) {
public let equal = bindCompare<Int8>(val, Int8.equal, Int8.toText, "");
public let notEqual = bindCompare<Int8>(val, Int8.notEqual, Int8.toText, "!=");
public let less = bindCompare<Int8>(val, Int8.less, Int8.toText, "<");
public let lessOrEqual = bindCompare<Int8>(val, Int8.lessOrEqual, Int8.toText, "<=");
public let greater = bindCompare<Int8>(val, Int8.greater, Int8.toText, ">");
public let greaterOrEqual = bindCompare<Int8>(val, Int8.greaterOrEqual, Int8.toText, ">=");
public let equal = bindCompare(val, Int8.equal, Int8.toText, "");
public let notEqual = bindCompare(val, Int8.notEqual, Int8.toText, "!=");
public let less = bindCompare(val, Int8.less, Int8.toText, "<");
public let lessOrEqual = bindCompare(val, Int8.lessOrEqual, Int8.toText, "<=");
public let greater = bindCompare(val, Int8.greater, Int8.toText, ">");
public let greaterOrEqual = bindCompare(val, Int8.greaterOrEqual, Int8.toText, ">=");
};
};
Loading