Module
std.testing — the assertion vocabulary, and the conventions that hold until wolf test exists (s39). Stability tier: core.
**assert(cond) and assert(cond, msg) are INTRINSICS, not functions here.** One name in both tiers — comptime witness (s16) and runtime user trap ([conf.trap.map]: assert) — silent and effect-free when satisfied, trapping at the call's span when not. This module deliberately defines nothing called assert: a module item shadows the intrinsic module-wide (file boundaries create no scopes) and there is no arity overloading, so a helper named assert would sever every function here from the trap it raises.
The two-argument form WORKS at these pins and the sc01 interim is retired with this sprint. It landed broken — assert(1 == 1, "msg") trapped even when the condition held (F-0020) — so sc01 through sc05 wrote if !cond { testing.fail(msg) } everywhere. That spelling is no longer required: assert(cond, msg) is the msg-carrying assertion, msg is evaluated only on the failing path, and both implementations agree. The old spelling still works and the existing tests were not churned to change it.
A trap ends the process, so trap-testing is the RIG's job (D30: no unwinding, no catch, no recover — this track will not be the one to bend it). The convention that follows, binding for every sc sprint and restated in API-CONVENTIONS §13:
- Happy-path assertions GROUP into one entry file per theme. Grouping is safe only because none of them trap when the code is right. - Every trap expectation is its OWN entry file, with check: run(exit=trap(kind)) naming the kind. One trap ends the program, so a second expectation in the same file would never run. - Error-row expectations assert through else |Tag(p)|, tag AND payload — the binding in else |e| is the tag itself and has no members (std.errors' test is the worked example). - Table tests are a List of tuples plus a loop, until closures (c05). - Golden output rides the directive's stdout= hash; fixtures are shared, never inlined twice.
cargo xtask std-test --lint-conventions checks the mechanical half of that list, so it is a gate rather than a wish.
What executes, and what is freight. Five of the twelve functions below are monomorphic and run: fail, unreachable, todo, assert_near, assert_ulps. The comparison family — assert_eq, assert_ne, assert_lt, assert_le, assert_gt, assert_ge, assert_contains — is generic over cmp.Eq/cmp.Ord, and NO implementation executes trait dispatch at these pins (F-0002, F-0004): the bodies typecheck against their bounds through wolfc's mem rung and run nowhere. That is stated per function rather than hidden, and it is the single largest reason this module is smaller in practice than it looks: at these pins the assertion a test actually writes is assert(a == b, "…") on concrete types, and these helpers are the names that become useful the day dispatch lands.
The thirteenth is in the nursery. assert_starts_with lives in std/x/testing_text, and the measurement that put it there is worth recording: a builtin str method ANYWHERE in this module makes every importer of std.testing unsupported at resolve under wolfc (F-0018's resolve-level half). One helper would have cost the whole assertion floor its compiler lane — fail, unreachable and todo run there today — so it waits outside the facade and graduates in verbatim when str methods resolve.
Rendering stops at the relation. No helper renders the values it compared: a generic renderer needs Show (F-0033) and the s38 dispatch hook. assert_eq says which side of the relation broke and nothing else — a diff that lies about types would be worse than a sentence that admits it cannot show them.
Functions and methods
fn · Source line 81
pub fn fail(msg: str)
Unconditional failure: prints msg on one line, then traps assert ([conf.trap.map]). Never returns normally.
Example (prose — a trapping call cannot sit in a boolean example): testing.fail("unreached branch") prints FAILED: unreached branch and traps assert.
fn · Source line 88
pub fn unreachable()
Marks code that must never execute; reaching it is the bug. Traps assert via fail. Never returns normally.
fn · Source line 94
pub fn todo(msg: str)
Marks unfinished code: reaching it traps assert via fail, naming msg as what remains to build. Never returns normally.
fn · Source line 104
pub fn assert_eq[T: cmp.Eq](a: T, b: T)
Asserts a equals b under cmp.Eq; a miss prints one line and traps assert. Values are not rendered (Show, F-0033).
BLOCKED from executing: trait dispatch runs in no implementation at these pins (F-0002 / F-0004), so this body's evidence is its static ladder. Write assert(a == b, "…") on concrete types meanwhile.
fn · Source line 112
pub fn assert_ne[T: cmp.Eq](a: T, b: T)
Asserts a differs from b under cmp.Eq; equality prints one line and traps assert. Values are not rendered (Show, F-0033).
BLOCKED from executing, as assert_eq (F-0002 / F-0004).
fn · Source line 124
pub fn assert_lt[T: cmp.Ord](a: T, b: T)
Asserts a < b under cmp.Ord. A miss prints one line and traps assert.
BLOCKED from executing (F-0002 / F-0004), and doubly so for a reason worth knowing: the verdict comes back as a cmp.Ordering, and an enum's values cross a module boundary while nothing that INSPECTS them does (F-0029) — so even with dispatch, reading this result outside std.cmp needs that filing closed too.
fn · Source line 131
pub fn assert_le[T: cmp.Ord](a: T, b: T)
Asserts a <= b under cmp.Ord. A miss prints one line and traps assert. BLOCKED from executing exactly as assert_lt.
fn · Source line 138
pub fn assert_gt[T: cmp.Ord](a: T, b: T)
Asserts a > b under cmp.Ord. A miss prints one line and traps assert. BLOCKED from executing exactly as assert_lt.
fn · Source line 145
pub fn assert_ge[T: cmp.Ord](a: T, b: T)
Asserts a >= b under cmp.Ord. A miss prints one line and traps assert. BLOCKED from executing exactly as assert_lt.
fn · Source line 156
pub fn assert_contains[T: cmp.Eq](xs: List[T], x: T)
Asserts xs contains an element equal to x under cmp.Eq. A miss prints one line and traps assert.
BLOCKED from executing (F-0002 / F-0004): the same bound, the same dispatch. The list is read once and iterated once, so the body is clean under the mem tier either way.
fn · Source line 181
pub fn assert_near(a: f64, b: f64, eps: f64)
Asserts a and b are within eps of each other — the absolute tolerance form, for a magnitude the test already knows.
NaN never passes: every comparison against NaN is false, so assert_near(nan, nan, 1.0) traps. That is deliberate — a test comparing two NaNs wants float.is_nan on each, and a tolerance says nothing about a value that has no magnitude. +inf against +inf passes, since their difference is not taken until they differ.
eps is used as written; a negative eps can never be satisfied and is not diagnosed (the caller's arithmetic, not this function's).
Traps assert on a miss, after one line. Executes on every lane that has f64 at all (lupin and the native rung; the checked tier refuses float literals, F-0026).
fn · Source line 210
pub fn assert_ulps(a: f64, b: f64, n: int)
Asserts a and b are at most n representable steps apart — the RELATIVE tolerance a float test actually wants, in the currency std.math.float documents its accuracy in (sc04's ulp harness).
The distance is counted over IEEE totalOrder keys, so it is exact at every magnitude including across zero (-0.0 and +0.0 are one step apart, not zero: they are distinct bit patterns, which is what a bit distance measures) and it never traps on overflow.
NaN matches NaN and nothing else: two NaNs of any payload pass at any n, a NaN against a number never passes. Infinities are ordinary keys — f_max and +inf are one step apart.
Traps assert on a miss, after one line. Executes on lupin and the native rung.