Skip to content

Docs/Toolchain/Testing

Testing

fid test, assertions, the test module, and how the compiler tests itself.

~2 min read

On this page

fid test

Write each test as a function named test_*, in a file with no main:

fn add(a: i64, b: i64) -> i64 { return a + b; }

fn test_add() {
    assert_eq(add(2, 3), 5);
}

fn test_negative() {
    assert(add(-2, -3) < 0);
}
fid test math_test.fd

Each test runs in its own process, so a panic fails that test only; fid test prints ok or FAIL per test and a total. Functions named bench_* are timed. (fid test writes temporary _fides_test_run.* files in the current directory.)

Assertions

Built in, no import needed:

assert(cond);
assert_eq(actual, expected);
assert_msg(cond, "message");
assert_eq_msg(actual, expected, "message");

A failed assertion panics with Assertion failed; use the _msg forms to say which check failed.

The test module

use test gives a TestRunner with named tests and a summary. Its assertions return bool; record each result with test_pass / test_fail:

use test;

fn check(r: &mut TestRunner, ok: bool, name: str) {
    if ok { test_pass(r); } else { test_fail(r, name); }
}

fn main() -> i64 {
    var r = test_runner_new();
    test_begin(&mut r, "arithmetic");
    check(&mut r, test_assert_eq(2 + 2, 4, "addition"), "addition");
    check(&mut r, test_assert_approx_eq(1.0 / 3.0, 0.333, 0.001, "division"), "division");
    test_summary(r);
    return 0;
}

Assertions: test_assert_eq, _ne, _true, _false, _gt, _lt, _in_range, _str_eq, _approx_eq, _empty, _len, _contains; test_assert_or_abort and test_assert_eq_or_abort panic at once.

#[test], #[should_panic] and #[ignore] parse but do nothing yet; name tests test_* instead.

How the compiler tests itself

fidesc test --compiler fid runs every program in tests/bootstrap/ (572 files, Nov 15) through the interpreter, the C backend and the native backend, and compares each backend’s output with the interpreter’s. --fail runs the programs that must be rejected (125 *_fail.fd files) and checks each fails for the reason its // expect-error: line names. verify-selfhost.sh runs the 51 tests of the compiler’s own components.

The last full run was on Nov 2, 2026, with fidesc as the compiler under test: interpreter 339/339, C 343/343, native 345/345, expected failures 89/89. The suite has not been rerun with fid; changes since then were checked with their own tests. tests/conformance/ adds 104 programs, each checking one rule of the language reference.

Report an issue