docs / Getting Started / Testing

Testing

system.testing provides four assertion intrinsics. Each is lowered directly by the compiler — the abort path is synthesized at the call site, embedding the source path:line in the failure message.

use system.io
use system.testing

fn add(a int, b int) int
    a + b

fn main()
    // Pass silently.
    assert_eq(add(2, 3), 5)
    assert(add(1, 1) == 2, "addition should be commutative")
    assert_ne(add(2, 2), 5)

    // A failing assertion aborts with:
    //   Runtime error: assertion failed at <path>:<line>: expected 6, got 5
    // assert_eq(add(2, 3), 6)

    // assert_panics catches Miri-level panic(...) calls.
    assert_panics(fn(): panic("boom"), "boom")
FunctionBehaviour
assert(cond, msg?)Aborts when cond is false.
assert_eq<T>(actual, expected, msg?)Aborts when values differ. Supports int/float/bool/String + all int widths.
assert_ne<T>(a, b, msg?)Aborts when values are equal.
assert_panics(f, expected?)Runs f() and aborts unless it calls panic(...).

A failed assertion aborts with Runtime error: assertion failed at <path>:<line>: <detail>. assert_panics uses a setjmp/longjmp catch frame so a Miri-level panic(...) inside the closure is caught and reported as a pass.