| | @@ -1,103 +0,0 @@ |
| 1 | | -# Testing: Rand, Check, Prop and raztest |
| 2 | | - |
| 3 | | -A plan for testing raz programs: three library modules and a tool, all |
| 4 | | -shipped with raz, so that a public project needs nothing past raz, make |
| 5 | | -and sh to use them. Each step is a commit of its own, useful alone; |
| 6 | | -after each, stop for review. |
| 7 | | - |
| 8 | | -## Why here |
| 9 | | - |
| 10 | | -- Every program has the library, and a program's make already builds |
| 11 | | - `tools/Pretty.raz` for `fmt`; `raztest` is found the same way. |
| 12 | | -- Today ~180 `check`/`expect` helpers are written by hand across ~/r, |
| 13 | | - four projects carry a PRNG of their own (rjson, pict, sauce, tasta), |
| 14 | | - and each Makefile hand-rolls its test loop and summary. |
| 15 | | - |
| 16 | | -## The pieces |
| 17 | | - |
| 18 | | -| Piece | Where | Size | What | |
| 19 | | -|---|---|---|---| |
| 20 | | -| `Rand` | `lib/Rand.raz` | ~40 | a seeded generator, splitmix64 | |
| 21 | | -| `Check` | `lib/Check.raz` | ~80 | assertions, failures on stderr, status by `Rt.atExit` | |
| 22 | | -| `Prop` | `lib/Prop.raz` | ~300 | properties and fuzzing over recorded choices, with shrinking | |
| 23 | | -| `raztest` | `tools/Test.raz` | ~700 | finds, builds and runs tests; colour, reports, watch | |
| 24 | | - |
| 25 | | -**Rand.** `init(r, seed)`, `next(r): U64`, `below(r, n)` (no bias), |
| 26 | | -`range(r, lo, hi)`, `seed(): U64` (fresh, from `Sys.random`, to print |
| 27 | | -and replay). No reals until a user needs them. |
| 28 | | - |
| 29 | | -**Check.** `ok(cond, what)`, `str(what, got, want)` (escaped), |
| 30 | | -`int(what, got, want)`, `mute(on)` and `mutedFailures()` for Prop. A failure is a block on |
| 31 | | -standard error: |
| 32 | | - |
| 33 | | - FAIL what |
| 34 | | - got: "..." |
| 35 | | - want: "..." |
| 36 | | - |
| 37 | | -and a program with failures ends with `Check: F of N failed` and status |
| 38 | | -1, by a procedure registered with `Rt.atExit` (which may call |
| 39 | | -`Rt.exit` itself), so there is no `done` to forget. A passing run says |
| 40 | | -nothing. The status and this text are the whole contract with |
| 41 | | -`raztest`; a bare `./Mod` or a make loop works as before. |
| 42 | | - |
| 43 | | -**Prop.** A property is `proc(var s: Prop.Source)` that draws values |
| 44 | | -(`int(s, lo, hi)`, `bool(s)`, `bytes(s, max, buf)`, `pick(s, n)`) and |
| 45 | | -checks them with `Check`. A case is the bytes it drew (as Hypothesis |
| 46 | | -does), so shrinking works on those bytes (cut chunks, zero, lower) and |
| 47 | | -replays the property: no shrinker per type, no closures. A number is 8 |
| 48 | | -bytes, big-endian, lowered as a whole; `bytes` puts before each byte |
| 49 | | -one that may end them, so that they shrink one by one. A property |
| 50 | | -reading only `bytes` is a byte fuzzer. While searching, `Check` is |
| 51 | | -muted; the smallest failing case is run again aloud and saved to |
| 52 | | -`test/seeds/<name>`; saved seeds are replayed first, every run. |
| 53 | | -`PROP_SEED` replays a run's fresh cases, `PROP_CASES` sets how many |
| 54 | | -(100), `PROP_TIME=60` fuzzes for a minute, `PROP_DIR` moves the seeds; |
| 55 | | -a case that crashes is saved at exit. |
| 56 | | - |
| 57 | | -**raztest.** Finds modules with `proc main*` in `src/` and `test/*.raz` |
| 58 | | -(`-I`, default `src`); builds with `-Werror`; runs them, `-j n`, a |
| 59 | | -timeout each, `-r pattern`; times each; shows a test's output only when |
| 60 | | -it fails; colour on a terminal unless `CI` or `NO_COLOR`; a summary and |
| 61 | | -the status. `--tap`, `--junit file` (a module is a case, its `FAIL` |
| 62 | | -blocks the failure). `-w` reruns every test when a `.raz` beside the |
| 63 | | -tests or in `-I` changes (raz builds fast; import tracking isn't worth |
| 64 | | -its lines), by polling file times (Sys has no inotify: a gap). `--seed`, `--fuzz 60s` |
| 65 | | -set `PROP_*`. Left out: `.cn`, sh and pty tests, which stay in make. A |
| 66 | | -Makefile uses `raztest` when it's there and its own loop when not. |
| 67 | | - |
| 68 | | -## Steps |
| 69 | | - |
| 70 | | -1. `Rand`, with its self-test. |
| 71 | | - Done: `lib/Rand.raz`, splitmix64. |
| 72 | | -2. `Check`; the library's self-tests use it. |
| 73 | | - Done: `lib/Check.raz`. |
| 74 | | -3. `raztest`: finding, building, running, `-j`, timeouts, colour, |
| 75 | | - summary; `test/check.sh`'s library loop uses it. `TOOLS` gains |
| 76 | | - `Test`; `make install` puts `raztest` on PATH; `doc/raztest.1`. |
| 77 | | - Done: `tools/Test.raz`. |
| 78 | | -4. `raztest --tap`, `--junit`. |
| 79 | | - Done. |
| 80 | | -5. `raztest -w`. |
| 81 | | - Done. |
| 82 | | -6. `Prop`, with its self-test. |
| 83 | | - Done: `lib/Prop.raz`. |
| 84 | | -7. Volume 2: `Rand`, `Check` and `Prop` go into `doc/raz-lib.md` as |
| 85 | | - standard library (not core: `conform/` is untouched), with whole |
| 86 | | - examples, once the first users have settled them; one report |
| 87 | | - version. `STANDARDS.md` says how a module tests itself with them. |
| 88 | | - Done: report 2026-10.36, `doc/raz-lib.md`, `STANDARDS.md`. |
| 89 | | -8. robbie: `robbie -w`, in its own repository. |
| 90 | | - |
| 91 | | -After the release that brings them: rjson, pict and sauce take `Rand` |
| 92 | | -and `Prop` (rjson's `Random.raz`, JSONTestSuite as seeds; pict's fuzz; |
| 93 | | -sauce's `Fuzz.raz` draws), and projects take `Check` and `raztest` as |
| 94 | | -their files are touched, with no sweep. `desktop.7` names `raztest` |
| 95 | | -once it is installed. |
| 96 | | - |
| 97 | | -## Left out |
| 98 | | - |
| 99 | | -Coverage-guided fuzzing (the compiler would have to count branches); |
| 100 | | -tests in doc comments (no library comment holds a whole example; the |
| 101 | | -report's and the tutorial's are already run); a shared pty harness |
| 102 | | -(belongs with rtui or rterm); `Check` naming the failing line (`Rt` |
| 103 | | -knows places but exports none: a gap). |