# Testing
```sh
make test-pic # crash, tool, provider, session, TUI and unit suites; ASan/UBSan and release builds
make test-docs # the reference against the code, the README budget, links
make bench-pic # compare timings with bench/baselines/<OS>-<arch>.tsv
```
`make test-pic` runs every suite in parallel, one job per core (`JOBS=1` for the serial order); each
script keeps its output in `build/pic/logs` and prints it only when it fails. Tests never touch the
real `~/.pic`: they run with a private `HOME` and `PIC_MODEL_CATALOG=offline`. `test/run-logged.sh`
sets `PIC_TEST_PRIVATE_HOME`, under which a pic whose `HOME` is the account's own refuses to start,
and `make test-docs` fails for a test script that runs pic and never sets `HOME`. `make install-pic`
runs the whole suite before it installs.
CI runs the same suite on every check-in and gates trunk. [Landing](landing.md) has the details.
Changes are also run under [Fil-C](https://fil-c.org), where any memory error is a crash
(`tools/remote/`). [Fil-C](filc.md) says how to run it.
## Exact-capacity tests
`make test-capacity` (part of `make test-pic`) calls each parser and decoder that fills a caller's
buffer with a heap buffer of exactly the size it needs, and one byte less where the function takes a
capacity, in the ASan/UBSan build: a sanitizer sees only a write that happens, and a generous stack
buffer hides an off-by-one. It covers the Noise handshakes, transport records and offer, base64 and base64url, Web Push
(origin, VAPID header, topic, aes128gcm body), the SSE framer's line, data, event and id limits,
sqlar, the HTTP response parser's header fields, image sniffing and inspection on every prefix of a
real header, sealed credential rows (`pic_cred_seal`, `pic_cred_box` and their openers), the PKCE
and random helpers, the key-health sentences, the provider helpers (`pic_json_get`,
`pic_auth_line`, `pic_model_url`, `pic_cost_json`, `pic_sb_add`), the endpoint URL check, an OAuth
query's percent decoder, the URL splitters of web_fetch and the HTTP client, and the terminal UI's
parsers and formatters (`mj_parse`, themes and colours, the key list, durations, sizes, the
settings panel's value, the done signal, the `@file` token). A parser that takes a length is fed
text of exactly that length with no NUL after it. The fuzz targets are not part of it. A new
function with an output capacity gets a case in `test/pic/test_capacity.c`.
## Compilers
The build uses `CC` (default `cc`) and compiles with `-Werror`; it is warning-clean under clang and
gcc (`make CC=gcc-16 pic`). gcc's `-Wformat-truncation`, which clang does not have, is off: a
clipped error or display string is the intended outcome there.
## Fuzzing
`make fuzz-decode`, `fuzz-http`, `fuzz-chat` and `fuzz-responses` need an LLVM clang with libFuzzer;
`FUZZ_SECONDS` bounds a run. CI runs each for 30 seconds when the runner has one.
## Generated files
`src/changelog.inc` is built from `CHANGELOG.md` by `tools/changelog-inc.sh`, and `src/manual.inc`
from docs/manual and docs/reference by `tools/manual-inc.sh`; neither is committed.
`test/pic/help.sh` checks that `pic help TOPIC` prints each file exactly and that `pic --help` stays
within 40 lines and 100 columns. The key table in `docs/reference/keys.md` is generated from
`src/tui/keymap.c` by `sh test/pic/docs.sh --keys`, and `make test-docs` fails when they differ.