Testing framework with assertions and test runners. A test can also fix the clock (set-now, advance), deliver events to their handlers (deliver) and fire due schedules (run-due).

Values

empty-test-counter

empty-test-counter: Map {
  passed: 0,
  failed: 0,
  total: 0
}

max-test-deliveries

max-test-deliveries: Int 10000

Functions

assert core

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

Assert that actual is truthy (not null, not false, not an error Result).

Example

test-truthy meta ["test"] fn () {
    assert(gt(5, 3), "5 should be greater than 3")
    assert(contains("hello", "ell"))
    response {id: "r-1"}
    assert(response.id, "response should have an id")
}

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 meta ["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("::myapp::checkout-test/test-total", true)  // true = capture output

advance

fn (duration: ::hot::time/Duration): ::hot::time/Instant

Move this test's clock by duration and return the new time. Years and months have no fixed length, so use weeks, days or smaller units. A zero duration is an error, since the clock would not move. A clock the test has not fixed is fixed at the real time first.

Example

::hot::test/set-now("2026-10-14T09:00:00Z")
::hot::test/advance(::hot::time/hours(5))
Str(::hot::time/now())  // "2026-10-14T14:00:00Z"

clear-now

fn (): Null

Return this test's clock to the real time.

Example

::hot::test/set-now("2026-10-14T09:00:00Z")
::hot::test/clear-now()
::hot::time/now()  // the real time again

deliver

fn (): Vec<Map>
fn (event: Map): Vec<Map>

Deliver event, a map with type and data, to its on-event handlers, run inside this test; then deliver the events they send, until none is left. With no argument, deliver the events sent so far.

In a test, send keeps an event instead of publishing it, and nothing runs until the test delivers it. A delivered hot:schedule:new arms a schedule for run-due, with a relative time such as "in 1 day" counted from when it was sent, and hot:schedule:cancel disarms. A handler that fails counts as a failed assertion; one that cancels does not, and the other handlers still run. Retries do not apply. Returns one {type, fn, result} per handler run.

Example

runs ::hot::test/deliver({type: "order:placed", data: {id: "o-1"}})
assert-eq(["::shop::orders/on-placed"], map(runs, %.fn))

is-test

fn (f)

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

Example

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

::hot::test/is-test(my-test)   // true
::hot::test/is-test(other-fn)  // false

ptap

fn (x)

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

Example

[1, 2, 3] |> ::hot::test/ptap() |> map(mul(%, 2))
// Prints: 1, 2, 3
// Returns: [2, 4, 6]

run-due

fn (): Vec<Map>

Fire each armed schedule due by this test's clock, soonest first, and deliver the events it sends. Each call runs with the clock at its due time, as the scheduler would have run it; afterwards the clock is back where the test left it. A recurring schedule fires once for each occurrence that is due. A call that fails counts as a failed assertion. Returns one {type, fn, result} per call and handler run; a scheduled call has type "hot:schedule" and its due time in at.

run-due first delivers the events sent so far, so a schedule sent before the clock moved is armed from the time it was sent.

Example

::hot::test/set-now("2026-10-14T09:00:00Z")
send("hot:schedule:new", {fn: "::app::steps/check-due", args: ["s-1"], schedule: "in 1 day"})
::hot::test/advance(::hot::time/days(2))
::hot::test/run-due()  // calls check-due("s-1") at 2026-10-15T09:00:00Z

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
::hot::test/run-matching-tests("math", true)

// Run tests matching "coll" with full output
::hot::test/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
::hot::test/run-tests(true)

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

schedules

fn (): Vec<Map>

The schedules armed in this test and not yet fired, soonest first, each {id, fn, args, at}.

Example

::hot::test/deliver()
first(::hot::test/schedules()).fn  // "::app::steps/check-due"

set-now

fn (time: Str | ::hot::time/Instant | ::hot::time/ZonedDateTime): ::hot::time/Instant

Fix this test's clock at time, an RFC 3339 string, Instant or ZonedDateTime, and return it as an Instant. ::hot::time/now, now-zoned and the other "now" functions return it, in this test and in the handlers it delivers to, until the test sets, advances or clears it. Each test starts on the real clock.

Example

::hot::test/set-now("2026-10-14T09:00:00Z")
Str(::hot::time/now())  // "2026-10-14T09:00:00Z"