0269. In-language test blocks and tenon test unit discovery
- Status: Accepted
- Date: 2026-11-22
- Plan: M16.13
- Review: —
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
- Syntax. Top-level compact record
Tname:body(ordinary spellingtest name { … }). Body is an ordinary statement block. Tests are neverpub, never imported, and never part of a library's public API. - Assertions. Calls
assert(cond: bool)andassert_eq(left, right)(equality types only) are rewritten only insidetestbodies. Outside tests they remain ordinary unresolved calls. Failures print a stable message with source span and, forassert_eq, left/right values, then the harness exits 1 via existing IRPrint/Exit(no new interpreter opcodes). - Exclusion. Normal
build/run/emit-*striptestitems before lowering (like derives).checkstill typechecks them so they do not bit-rot.tenon testexpands tests into private harness functions plus a syntheticmain(cli: Cli)that reports results. - Discovery / CLI.
tenon test <dir> [--filter SUB] [--timeout-ms N]keeps application fixtures and also runs unit tests found as immediate.tnchildren of<dir>that contain aTname:record (lexical scan). Filter matches test names by substring.--timeout-msapplies to application fixtures; unit-test compile/run currently inherit process lifetime (follow-up). Human and--jsonreports share app-test exit codes: 0 all pass, 1 failures/no cases, 2 usage/invalid, 3 internal. - Backends. C path is required. Interpreter
runs the same lowered IR through a capturing host in
driver(nointerp*edits). If a future assert form needed a new trap kind, add it in the interpreter astrap: assert failed at file:line:col(exit 101) mirroring overflow traps—out of scope here because Print/Exit already cover messages. - Capabilities. The synthetic harness uses
cli.stdout/cli.stderr.tenon testtemporarily 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. - Format. New opcode
Tdoes not change encoding of existing items;FMT_VERSIONremains 1.
Alternatives considered
- Separate
tenon unitcommand — splits discovery from the documented test entry; rejected so one command owns both fixture and in-source tests. #[test]-style attributes on functions — compact Tenon has no attributes; a declaration opcode matches the grammar better.- New interpreter trap for asserts — clearer
for some tooling, but needs frozen
interp*edits; Print/Exit keep both backends without that.
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.