March Docs

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

fnassert_eqassert_eq(expected, actual, msg : String) : Unit#

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")
()
fnassert_eq_boolassert_eq_bool(a : Bool, b : Bool, msg : String) : Unit#

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")
()
fnassert_eq_intassert_eq_int(a : Int, b : Int, msg : String) : Unit#

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")
()
fnassert_eq_strassert_eq_str(a : String, b : String, msg : String) : Unit#

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")
()
fnassert_errassert_err(res : Result(a, e), msg : String) : e#

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"
fnassert_falseassert_false(cond : Bool, msg : String) : Unit#

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")
()
fnassert_neassert_ne(left, right, msg : String) : Unit#

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")
()
fnassert_noneassert_none(opt : Option(a), msg : String) : Unit#

Assert an Option is None. Returns (); panics if it is Some.

Examples

march> Test.assert_none(List.head_opt([]), "no head")
()
fnassert_okassert_ok(res : Result(a, e), msg : String) : a#

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")
5
fnassert_someassert_some(opt : Option(a), msg : String) : a#

Assert 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")
3
fnassert_trueassert_true(cond : Bool, msg : String) : Unit#

Assert that cond is true. Returns (); panics with "Assertion failed: " ++ msg if cond is false.

Examples

march> Test.assert_true(1 < 2, "ordered")
()
fnfailfail(msg : String) : Unit#

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