1500 Test Framework
Provium's test framework is implemented mostly in Lua and installed onto every
test file's state. This page documents every callable: test, todo,
wait_until, the t context, and the per-test metadata table.
1500.1 test(name, [meta,] fn) #
Register a test in declaration order. Two call shapes:
test
test
| Argument | Required | Type | Description |
|---|---|---|---|
name | yes | string | Test name. Must be unique within the file (duplicate names raise at registration). |
meta | no | table | Per-test metadata. See meta tags. |
fn | yes | function | The test body, called with (t), the test context. |
Tests run sequentially in declaration order. Each test gets a fresh t
context. The harness wraps the call in pcall semantics, a Lua error()
becomes a Failed outcome; clean return becomes Passed; explicit t:skip()
becomes Skipped.
Duplicate names within a file error at registration time:
test: duplicate name `foo` in this file
1500.2 todo(reason?) #
Declarative file-scope skip. When called at top level (before any test()
body runs), every registered test is reported Skipped with the given
reason. Test bodies are not executed.
todo
test
test
-- Both report Skipped with reason "waiting on the spec".
Without an argument, defaults to "todo".
Skipped tests still emit TestSkipped events with the meta intact, so
coverage and dashboards see the same shape they would for an inline
t:skip().
1500.3 wait_until(predicate, opts?) #
Call predicate repeatedly until it returns truthy (and return that value),
or until the timeout lapses. Useful for polling guest-side conditions that
don't have a stream interface.
local pid = wait_until
Opts:
| Field | Default | Type | Description |
|---|---|---|---|
timeout | 10 | number (seconds) or string "30s" / "500ms" / "5m" / "2h" | Total time to wait before giving up. |
interval | 0.1 | number (seconds) | Time between predicate calls. |
desc | "condition" | string | Used in the timeout error message. |
On timeout, errors with wait_until: <desc> not met within <timeout>s. The
error includes the offending input (for example bad timeout string ...) when
the timeout argument is malformed.
The predicate runs under pcall, if it raises, the error propagates
immediately (with the raise location) rather than being treated as a "not yet"
signal.
wait_until uses wall-clock seconds, not CPU time, so the deadline elapses
while _provium_sleep is pausing.
1500.4 The t context #
A fresh t table is built per test. It carries the test's name and metadata,
and the runner keeps a sticky per-test failure record so a
pcall(t:assert(false)) is still classified as a failure (the inner pcall
swallows the raise, but the failure was recorded before it).
1500.4.1 Fields #
t.name, the test's name.t.meta, the per-test metadata table (or{}if none was given).
1500.4.2 Assertions #
Every assertion error includes the offending values in the message, assertion failures are self-explanatory without needing to read context.
1500.4.3 t:assert(cond, msg?) #
Raise if cond is falsy. msg is the failure message; defaults to
"assertion failed".
1500.4.4 t:assert_eq(a, b, msg?) #
Raise if a ~= b. The error message includes both values:
<msg>: <a> ~= <b>.
1500.4.5 t:assert_neq(a, b, msg?) #
Raise if a == b. Mirror of assert_eq.
1500.4.6 t:assert_contains(haystack, needle, msg?) #
Raise unless string.find(haystack, needle, 1, true) returns non-nil. Both
arguments must be strings; non-string args raise immediately with a "slice 2
limit" pointer.
1500.4.7 t:assert_raises(fn, msg?) #
Run fn under pcall and assert that it raised. Returns the error value if
the raise happened. Errors with <msg>: expected to raise if fn returned
cleanly.
The sticky failure record is saved before invoking fn and restored on a
successful raise, that way an assertion inside fn (used to trigger the
expected raise) doesn't poison the rest of the test.
1500.4.8 Skip and fail #
1500.4.9 t:fail(msg?) #
Mark the test failed and raise. msg defaults to
"explicit failure (t:fail)".
1500.4.10 t:skip(reason) #
Mark the test skipped and raise through the internal sentinel. reason is
recorded in the TestOutcome and emitted in the TestSkipped event.
test
1500.4.11 Logging #
1500.4.12 t:log(msg) #
Append msg (any value, converted through tostring) to the test's log
array. The log is included in the FileOutcome.tests[i].log and emitted
alongside TestPassed / TestFailed events.
Useful for diagnostic output that should accompany failures. Unlike print,
t:log is structured and tied to the specific test.
1500.5 Outcomes #
A test ends in one of three states:
| Status | Triggered by |
|---|---|
| Passed | Test fn returned without raising AND no assertion failure was recorded. |
| Failed | Test fn raised (through error(), t:assert*, t:fail), or a sticky assertion failure was recorded before a pcall caught the raise. A Rust panic during the test also marks Failed and poisons every subsequent test in the file. |
| Skipped | t:skip(reason) was called, OR meta.skip = true / meta.skip = "reason", OR --tag / --no-tag filtered the test out, OR --include-slow was off and meta.slow = true, OR file-scope todo() was called. |
A skipped test produces no event lifecycle other than TestSkipped. A failed
test additionally captures the last 4 KiB of every booted VM's console log
into the TestFailed.console_excerpt field, useful for diagnosing kernel-side
regressions without reproducing the run.
1500.6 Time and timeouts #
Per-test timeouts come from meta.timeout. File-default timeouts come from
provium.timeout. Per-test wins.
The watchdog fires by tearing down the entire file's lab, there is no
finer-grained cancellation in v1 because there is no cooperative cancel point
in the AgentClient ops. Practical implication: for files using
provium.reset_between_tests = true the lab is restored before the next test
anyway, so the lab-wide tear-down is harmless. For files that share live state
across tests, a per-test timeout invalidates the rest of the file. Don't put a
meta.timeout = N on a flaky test in a state-sharing file expecting siblings
to be unaffected.
1500.7 See also #
- Meta tags: full reference for
meta.slow,meta.tags,meta.skip,meta.timeout,meta.spec. - provium global,
provium.reset_between_tests,provium.timeout. - The test function: patterns for organizing a test file.