On this page

0269. In-language test blocks and tenon test unit discovery

Context

Application goldens (tenon test <dir> over tests/ fixtures) cover end-to-end CLI behaviour. They do not replace fast, co-located checks of pure helpers. Roadmap item 8 asks for test blocks with assertions inside .tn sources, run on both backends, without prerequisites. Compact Tenon is the only product syntax (ADR-0268); FMT_VERSION stays 1. Interpreter sources (interp*) are frozen for this change set.

Decision

  1. Syntax. Top-level compact record Tname:body (ordinary spelling test name { … }). Body is an ordinary statement block. Tests are never pub, never imported, and never part of a library's public API.
  2. Assertions. Calls assert(cond: bool) and assert_eq(left, right) (equality types only) are rewritten only inside test bodies. Outside tests they remain ordinary unresolved calls. Failures print a stable message with source span and, for assert_eq, left/right values, then the harness exits 1 via existing IR Print/Exit (no new interpreter opcodes).
  3. Exclusion. Normal build/run/emit-* strip test items before lowering (like derives). check still typechecks them so they do not bit-rot. tenon test expands tests into private harness functions plus a synthetic main(cli: Cli) that reports results.
  4. Discovery / CLI. tenon test <dir> [--filter SUB] [--timeout-ms N] keeps application fixtures and also runs unit tests found as immediate .tn children of <dir> that contain a Tname: record (lexical scan). Filter matches test names by substring. --timeout-ms applies to application fixtures; unit-test compile/run currently inherit process lifetime (follow-up). Human and --json reports share app-test exit codes: 0 all pass, 1 failures/no cases, 2 usage/invalid, 3 internal.
  5. Backends. C path is required. Interpreter runs the same lowered IR through a capturing host in driver (no interp* edits). If a future assert form needed a new trap kind, add it in the interpreter as trap: assert failed at file:line:col (exit 101) mirroring overflow traps—out of scope here because Print/Exit already cover messages.
  6. Capabilities. The synthetic harness uses cli.stdout / cli.stderr. tenon test temporarily grants those two capabilities for the package ceiling while compiling the harness; package manifests stay unchanged so libraries without I/O caps can still host pure unit tests.
  7. Format. New opcode T does not change encoding of existing items; FMT_VERSION remains 1.

Alternatives considered

Consequences

Compact grammar, AST, checker, strip/expand path, and tenon test gain unit tests. LANGUAGE.md and diagnostics document the surface. plugins/hsyntax dogfoods a few blocks; its Declaration reader/writer should learn T when parity benches next run. Plan task M16.13 lands this.