test — tests
mzs
include testWARNING
Not available in bot scripts. Tests run in the terminal: mzs test.
| Function | What it does |
|---|---|
test.case(name) { … } | runs the block as a named test → whether it passed |
test.eq(actual, expected) | an error if they are not equal; the message shows both values |
test.ne(actual, other) | an error if they are equal |
test.near(actual, expected, eps = 1e-9) | an error if the numbers are further apart than eps |
test.raises(kind = nil) { … } | an error if the block did not fail (with an error of kind kind) → the error dict |
test.skip(reason) | skips the test; outside a test, the rest of the file |
test.group(name) { … } | gives the tests inside a common prefix name › … |
A failed test does not stop the file, unlike assert.
Tests
mzs
include test
test.case("sums") { test.eq([1, 2, 3].sum, 6) } # → true
test.case("case") { test.eq("Yes".lower, "no") } # → false
test.case("after a failure") { assert(true) } # → truesh
mzs test demo_test.mzstext
demo_test.mzs
ok sums
FAIL case
expected "no", got "yes" (demo_test.mzs:3:26)
ok after a failure
1 file, 3 cases, 1 failed (1ms)Argument order: the actual value first, then the expected one. Equality is plain ==: test.eq(1, 1.0) passes.
Errors, floats, skips
mzs
include test
include json
test.case("broken JSON") {
e = test.raises("json") { json.parse("{") }
test.ne(e["message"], "")
}
test.case("sum of floats") { test.near(0.1 + 0.2, 0.3) }
test.case("later") { test.skip("not ready") }text
ok broken JSON
ok sum of floats
skip later (not ready)test.raises returns the same dict that try … else (e) gets: message, kind, data.
Groups
mzs
include test
test.group("rounding") {
test.case("up") { test.eq(2.5.round, 3) }
test.case("down") { test.eq(2.4.round, 2) }
}text
ok rounding › up
ok rounding › downThere are no setup/teardown hooks: shared setup is a function, cleanup is ensure.
A test file
The name is *_test.mzs; the code under test is included as a module.
mzs
# money_test.mzs
include test
include decimal
include money from "./money.mzs"
test.case("exact total") {
test.eq(money.total([decimal.of("10.10"), decimal.of("20.20")]), decimal.of("30.30"))
}sh
mzs test # every *_test.mzs in the folder and below
mzs test money_test.mzs # one file
mzs test --filter rounding # only matching names
mzs test --now 2026-03-05T12:00:00Z # the clock stands still, for date logictext
money_test.mzs
ok exact total
1 file, 1 case, 0 failed (1ms)- Exit code: 0 if everything passed (skips don't count), 1 if something failed.
- Each file is a separate run with its own globals and limits.
- A passing test's output is hidden, a failing one's is printed;
-vshows everything. - Flags:
--fail-fast,--json,--cover,--time,--rand.