Home / Learn / 14 Testing
Release v0.4.0Edition 0.2
14.9 Recap and reference
Page 10 of 10
14.9.1 For agents
una --json check . reports example mistakes in the same shape as any other. For a misspelled operation, with its exact edit:
json
{"schema":"una.diagnostics/1","diagnostics":[{"schema":"una.diagnostic/1","code":"U1001","severity":"error","domain":"names","message":"capability `Mailer` has no operation `sent`","primary":{"file":"src/checkout.una","start":{"line":139,"col":28},"end":{"line":139,"col":32}},"related":[],"repairs":[{"rank":1,"escape_cost":0,"description":"write `send`","edit":{"file":"src/checkout.una","start":{"line":139,"col":28},"end":{"line":139,"col":32},"replacement":"send"}}],"explain":"una explain U1001"}],"fixable":1}una --json test . prints una.test/1. Each example has outcome, reason, the expectation that failed with its file and line, the result, and the trace. Each event of a trace has seq, instance, capability, op, args and outcome, so an agent can check arguments that expect performed does not. For the dropped zero of section 14.4:
json
{"schema":"una.test/1","tier":1,"redacted":false,"diagnostics":[],"examples":[{"module":"shipping","name":"an order of 49.99 pays 4.90","outcome":"fail","reason":"it is false, with `result` = `49`","expectation":{"file":"src/shipping.una","line":24,"text":"expect result == 490"},"result":{"kind":"ok","value":"49"},"trace":[]},{"module":"shipping","name":"an order of exactly 50.00 ships for free","outcome":"pass","reason":null,"expectation":null,"result":{"kind":"ok","value":"0"},"trace":[]}],"passed":1,"failed":1}The compact rule: an example has given lines for every capability its do line needs, one do line, and one or more expect lines; it never uses a host capability.
14.9.2 Recap
- Write an
examplenext to the code: a name a reader understands, onedoline, andexpectlines that must hold. una test .checks the package, runs every example in a fresh machine, and exits with code 1 when one fails.- Give every failure path its own example with
expect fails, naming a variant of thedocall's error kind. - Replace each service with a fake handler installed by
given. Examples never use host capabilities. - Check effects with
expect performedandexpect not performed: what a call must do, and what it must not. - A fake is checked against the operations it implements, so it keeps their promises.
- Prove in
ensureswhat must hold for every input; pin exact values, the edges of each rule, and effects with examples.
14.9.3 Reference
- Construct pages:
example,handler,with,capabilityandop,ensures,attempt - Diagnostics: U0101, U1001, U1002, U2001, U3001, U3014, U5001
- Specification: requirements and examples, capabilities and effects, verification, dynamic semantics (traces and the example harness), diagnostics and the command line