Test
Test module: lightweight assertion helpers for in-process testing.
Tests are plain March functions; a test passes if it returns without calling panic/fail. Use these helpers to make assertions. Every helper returns normally (with () or the unwrapped value) when the assertion holds and panics with a message naming msg when not.
Functions
Assert two values are structurally equal (generic).
Uses March's built-in structural equality (the == operator), so this works on any types that aren't functions or opaque resources — ints, strings, booleans, floats, tuples, records, ADT variants, lists, and combinations of them.
On failure, both values are rendered via to_string (same form as inspect/debug) and included in the panic message so failures are easy to diagnose.
Note the argument order: the expected value comes first.
Examples
march> Test.assert_eq((1, "a"), (1, "a"), "tuple equal")
()
march> Test.assert_eq(Some([1, 2]), Some(List.reverse([2, 1])), "option equal")
()Assert two booleans are equal; a is the value under test, b the expected value. Returns (); panics with both values on mismatch.
Examples
march> Test.assert_eq_bool(List.is_empty([]), true, "empty")
()Assert two ints are equal. Note the argument order: a is the value under test ("got") and b the expected value (the reverse of assert_eq). Returns (); panics with both values on mismatch.
Examples
march> Test.assert_eq_int(2 + 2, 4, "sum")
()Assert two strings are equal; a is the value under test, b the expected value. Returns (); panics with both strings (quoted) on mismatch.
Examples
march> Test.assert_eq_str(String.to_uppercase("ok"), "OK", "upper")
()Assert a Result is Err and return the error value, so the error can be checked further. Panics if it is Ok.
Examples
march> Test.assert_err(Err("boom"), "should fail")
"boom"Assert that cond is false. Returns (); panics with a message containing msg if cond is true.
Examples
march> Test.assert_false(String.is_empty("x"), "non-empty")
()Assert two values are not structurally equal.
Counterpart to assert_eq; panics if the values compare equal via ==. Useful for checking that mutation/update paths actually changed something. On failure the message shows the (shared) value via to_string.
Examples
march> Test.assert_ne([1, 2], List.reverse([1, 2]), "reversed")
()Assert an Option is None. Returns (); panics if it is Some.
Examples
march> Test.assert_none(List.head_opt([]), "no head")
()Assert a Result is Ok and return the inner value. Panics if it is Err (the error value itself is not included in the message).
Examples
march> Test.assert_ok(Ok(5), "parsed")
5Assert an Option is Some and return the inner value, so the result can be used in further assertions. Panics if it is None.
Examples
march> Test.assert_some(List.head_opt([3, 4]), "has a head")
3Assert that cond is true. Returns (); panics with "Assertion failed: " ++ msg if cond is false.
Examples
march> Test.assert_true(1 < 2, "ordered")
()Fail immediately: panics with "FAIL: " ++ msg. Never returns; the Unit return type only lets it sit in any branch of a test.
if not(ok) do Test.fail("handshake never completed") else () end