Application golden tests and in-language unit tests
Run
tenon test <dir> [--filter SUB] [--timeout-ms N] [--json]
to check a trusted application's observable behavior on native C
and the interpreter, and to run in-language test
blocks found in package .tn files (ADR-0269). Unit
cases are named unit::<module>::<test>;
--filter matches those test names. Application
fixture cases keep their directory names. Each application case
checks both backends against the same expected bytes and against
each other. Install or build Tenon and make a C compiler available
before running a suite; the command needs the native compiler even
when investigating interpreter behavior. Exit codes match the
fixture suite: 0 all pass, 1 failures or no cases, 2 usage/invalid
fixture, 3 internal.
Try the example tools
Start in a Tenon checkout with target/debug/tenon
built, or set tenon below to an absolute path to your
installed executable. These commands copy the actual head,
its imported helper,
and csv-sum,
without changing their source. The existing fixtures include
binary head output, signed CSV amounts and invalid CSV that
legitimately exits 1.
checkout="$(pwd)"
tenon="$checkout/target/debug/tenon"
example="$(mktemp -d "${TMPDIR:-/tmp}/tenon-app-tests.XXXXXX")"
project="$example/app"
mkdir -p "$project/tests/head-prefix" "$project/tests/csv-signed" "$project/tests/csv-invalid" "$example/outside"
cp "$checkout/examples/tools/head.tn" \
"$checkout/examples/tools/head_config.tn" \
"$checkout/examples/tools/csv-sum.tn" "$project/"
printf 'head.tn\n' > "$project/tests/head-prefix/source"
printf -- '-n\n2\n' > "$project/tests/head-prefix/args"
printf 'alpha\nbeta\ngamma\n' > "$project/tests/head-prefix/stdin"
printf 'alpha\nbeta\n' > "$project/tests/head-prefix/expected.out"
printf 'csv-sum.tn\n' > "$project/tests/csv-signed/source"
printf 'a,10\nb,-3\n' > "$project/tests/csv-signed/stdin"
printf '7\n' > "$project/tests/csv-signed/expected.out"
printf 'csv-sum.tn\n' > "$project/tests/csv-invalid/source"
printf 'a,notanumber\n' > "$project/tests/csv-invalid/stdin"
printf '1\n' > "$project/tests/csv-invalid/expected.exit"
(cd "$example/outside" && "$tenon" test "$project" --json)
The invocation runs outside the project. A passing summary has
total: 3, passed: 3,
failed: 0, and exit 0. Expectations are never
automatically updated, including when the caller has
BLESS=1 set. To investigate a failure, run without
--json for a human report, inspect the named
case/backend/field, and correct the program or deliberately edit
the expected bytes.
Add a case
Each direct child directory of tests/ is a case,
sorted by UTF-8 name. Ordinary files directly inside
tests/ are ignored. For example:
app/
main.tn
tests/
sample/
expected.out
args
files/
input
| Case file | Meaning |
|---|---|
expected.out |
Required raw stdout bytes; an empty file expects no output. |
expected.err |
Raw stderr bytes; absent means empty. |
expected.exit |
Unsigned ASCII decimal exit code 0 through 255; absent means 0. |
stdin |
Raw input bytes; absent means EOF. |
args |
UTF-8, one literal argument per LF-delimited line. Spaces and empty arguments are retained; there is no shell parsing. |
env |
UTF-8, one distinct, nonempty KEY=VALUE per line,
split at the first =. No shell expansion occurs. |
files/ |
Regular input files and directories copied into each backend's
private working directory as files/. |
expected.file |
Raw expected bytes for tmp/out; a missing output
file fails even if the expectation is empty. |
source |
One project-relative .tn entry path; absent means
project main.tn. |
Trailing newlines and non-UTF-8 values matter in byte files. Text controls must be valid UTF-8 and cannot contain NUL. The command rejects symlinks and special files in fixture inputs. A source path cannot be absolute, traverse parents or resolve outside the project.
Arguments and environment values may contain
{case} and {tmp}. They expand to
. and tmp, respectively, for both
backends. For example, {case}/files/input addresses
the copied input and {tmp}/out is the checked output
location. Each backend starts with its own input copy and fresh
tmp/. Program arguments belong in args;
the test command rejects -- forwarding.
Sources stay in their original module and package context. Keep
imports beside their entry as normal: the example's
head.tn needs head_config.tn. A nested
entry uses its own directory for module/package resolution.
Packages must already have the locks, dependency trees and
generated companions ordinary offline compilation requires. The
command does not fetch, generate, enable development resolution,
run fixture hooks or invoke custom comparison commands.
The application receives a clean environment, with runner-owned
command lookup and the allowed values explicitly supplied by
env. The caller's application variables are not
inherited. Reserved keys are PATH, CC,
CFLAGS, CPPFLAGS, LDFLAGS,
TMPDIR, HOME,
XDG_CACHE_HOME, TENON_FFI_PREFIX,
TENON_CACHE_DIR, TENON_NO_CACHE and
TENON_CONTEXT_VC_INIT_CHILD. Prefixes
LD_, DYLD_, TRT_,
TENON_VC_, TENON_TEST_,
TVC_TEST_ and TVC_QUEUE_ are also
reserved. Ordinary application settings such as
TENON_BENCH_CHUNK=2 remain allowed. Compiler
preparation uses the normal invocation context; fixture
environment settings apply only to application execution.
Use trusted application code. Private working directories isolate fixture data; they do not provide OS containment or prevent arbitrary effects outside them.
Limits and failures
Initial fixture discovery and validation precede the case
budgets. Each case has one shared wall-clock deadline covering
copies of validated inputs into backend workspaces, native
build/execution, interpreter preparation/execution and pipe
completion. The default is 30,000 ms. Use
--timeout-ms N to choose an unsigned ASCII decimal
integer from 1 through 600,000 for every case. This cannot disable
or reset the deadline. Compiler/bootstrap prerequisite probes have
a separate bound.
On timeout, the case fails with its backend,
prepare or execute phase and configured
limit. Partial streams, exit, file and trap data are omitted; an
expected exit 101 cannot make a timeout pass. Cleanup completes
before a healthy next case starts with a fresh budget. If
ownership cannot be established during cleanup, the suite stops
and reports an internal error.
Combined stdout/stderr capture is limited to 1 MiB per stage. Requested output file reads have the same bound. Exceeding either is a failure, never a passing comparison of truncated output. Reports show the first differing zero-based byte offset, lengths and short hex excerpts; each detail is capped at 4,096 UTF-8 bytes before presentation escaping.
Actual application exits, including 1 or 2, and traps with exit
101 can pass when all expected bytes and status match. Compile
errors, signals, spawn failures and interpreter tool failures
cannot satisfy expected.exit. Trap stderr follows the
normal runtime contract; test reports do not yet attach a trap
stack.
| Suite exit | Meaning |
|---|---|
| 0 | Every case passed on both backends. |
| 1 | A mismatch, source/build/execution failure, timeout, or no cases. |
| 2 | Invalid usage/fixture or unavailable compiler prerequisite. |
| 3 | Internal or ownership failure. |
Mixed results retain the highest severity. A missing or empty
tests/ yields no_cases with zero counts.
Malformed fixtures yield invalid_fixture with zero
counts: the entire suite is validated before any application runs.
Unavailable or timed-out compiler/bootstrap prerequisites yield
missing_compiler.
With --json, stdout contains one summary object
with status, total, passed,
failed, cases and optional
error. Status is passed or
failed. Each case has name,
status, and failures; each failure
identifies backend (c,
interp, or both), field,
and bounded detail. Timeouts also carry
phase and limit_ms; compile failures may
include code. Suite errors have kind and
detail. Counts cover only reported cases; after a
fatal error, unexecuted cases are not counted as passed. Child
output is captured as data, never interpreted as report syntax.
See the command
reference for ordering and output-write error conventions.