Light Dark

Functions

assert core

fn (lazy actual: Any): Bool
fn (lazy actual: Any, description: Str): Bool

Assert that actual is truthy (with optional description).

Example

test-truthy #["test"] fn () {
    assert(gt(5, 3), "5 should be greater than 3")
    assert(contains("hello", "ell"))
}

assert-eq core

fn (lazy expected: Any, lazy actual: Any): Bool
fn (lazy expected: Any, lazy actual: Any, description: Str): Bool

Assert that expected equals actual (with optional description).

Example

test-math #["test"] fn () {
    assert-eq(4, add(2, 2), "2 + 2 should equal 4")
    assert-eq([1, 2], [1, 2])  // description auto-generated
}

run-test core

fn (f, capture-output)

Run a single test function with optional output capture.

Example

// Typically called by run-tests, not directly
run-test(my-test-fn, true)  // true = capture output

all-tests-passed

fn ()

Return true if all tests passed - helper to avoid scoping issues.

assert-expected-got

fn (expected, actual)

Format expected vs actual values.

assertion-failed

fn ()

Increment failed assertion counters.

assertion-failed-with-details

fn (test-name, assertion-description)

Record a failed assertion with test name and description.

assertion-passed

fn ()

Increment passed assertion counters.

call-with-capture

fn (f)

Call function f with stdout capture, discarding captured output.

current-test-assertions-passed

fn ()

Return true if current test has zero failed assertions.

current-test-reset

fn ()

Reset current test counters.

format-source-location

fn (source-info)

get-test-counters

fn ()

Get test counters from context, initializing if missing.

init-test-counters

fn ()

Initialize test counters in context.

is-test

fn (f)

Return true if function f is marked as a test via metadata.

Example

my-test #["test"] fn () { assert(true) }
other-fn fn () { "not a test" }

is-test(my-test)   // true
is-test(other-fn)  // false
fn (tests)

Print header for the test run and record start time.

fn ()

Print a summary of test results including failures and duration.

ptap

fn (x)

Debug helper: print each item in x and return x.

Example

[1, 2, 3] |> ptap |> map((x) { mul(x, 2) })
// Prints: 1, 2, 3
// Returns: [2, 4, 6]

run-matching-tests

fn (pattern, capture-output)

Run tests whose names contain pattern; return true if all passed.

Example

// Run only tests with "math" in the name
run-matching-tests("math", true)

// Run tests matching "coll" with full output
run-matching-tests("coll", false)

run-tests

fn (capture-output)

Discover and run all test functions; return true if all passed.

Example

// Run all tests with output capture
run-tests(true)

// Run all tests showing full output
run-tests(false)

set-test-counters

fn (counters)

Set test counters in context.

test-failed

fn (test-name)

Record a failed test and store enhanced name.

test-passed

fn ()

Increment passed test counters.