Test runner

Writing tests

Test blocks live alongside production code:

cleat
fn add(a: int, b: int) -> int {
    return a + b
}

test "addition" {
    assert(add(2, 3) == 5)
}

test "with message" {
    assert(add(0, 0) == 0, "zero plus zero should be zero")
}

Running tests

bash
cleat test main.cleat      # single file
cleat test myapp/           # directory
cleat test                  # uses cleat.toml entry

Output

text
=== RUN   test "addition"
--- PASS  test "addition"
=== RUN   test "with message"
--- PASS  test "with message"

2 tests: 2 passed, 0 failed

Exit code: 0 = all pass, 1 = failures.

Mocking with using

Override functions and tools in test blocks:

cleat
test "mock HTTP" {
    using fetch = fn(url: string) -> Result[string, string] {
        return Ok("mock response")
    }
    let r = fetch("any-url")
    assert(r.IsOk())
}

See Mocking with using for details.

Test blocks are excluded from production builds

cleat build ignores test blocks — they only compile in cleat test mode. No test code in production binaries.

Edit this page on GitHub