ReviewOS

also looking at this

zig-utils/zig-test-framework

Add reproducible randomized test order

#29
Merged glennmichael123 wants to merge codex/issue-14-random-order into main
18 files +487 -42
README.mdmodified+17-3
Changes to README.md
@@ -9,6 +9,7 @@ A modern, feature-rich testing framework for Zig inspired by Jest, Vitest, and B
99- **Async Test Support** - Full async test execution with concurrent and sequential modes
1010- **Timeout Handling** - Configurable timeouts at test, suite, and global levels with extension support
1111- **Retries & Repeats** - Re-run failures, stress-run selected tests, and report flaky outcomes
12- **Reproducible Randomization** - Shuffle suites and tests with replayable seeds
1213- **Familiar API** - Describe/it syntax similar to Jest and Vitest
1314- **Rich Assertions** - Comprehensive assertion library with `.expect()` and matchers
1415- **Error Assertions** - `toThrow()` and `toThrowError()` for testing error handling
@@ -102,6 +103,8 @@ This will automatically discover and run all `*.test.zig` files in the `tests` d
102103- `--retry <N>` - Retry a failed test or discovered test file up to N times
103104- `--repeat <N>` - Require N successful repetitions of every selected test
104105- `--fail-on-flaky` - Return a failing exit status when a retry recovers a failure
106- `--shuffle` - Randomize suites, tests, or discovered files with a generated seed
107- `--seed <N>` - Replay a randomized order; supplying a seed implies `--shuffle`
105108- `--shard-index <N>` - Run one one-based file shard
106109- `--shard-count <N>` - Set the total number of file shards
107110- `--no-color` - Disable color in child Zig test processes
@@ -139,6 +142,10 @@ zig-test --test-dir tests --retry 2 --fail-on-flaky
139142# Stress-run matching tests 100 times
140143zig-test --test-dir tests --filter parser --repeat 100
141144
145# Expose order dependencies, then replay the exact order with the printed seed
146zig-test --test-dir tests --shuffle
147zig-test --test-dir tests --seed 8675309
148
142149# Run the second of four deterministic file shards
143150zig-test --test-dir tests --shard-index 2 --shard-count 4
144151```
@@ -185,7 +192,9 @@ precedence over configured values.
185192 "filter": "database",
186193 "retries": 2,
187194 "repeat": 10,
188 "fail_on_flaky": true
195 "fail_on_flaky": true,
196 "shuffle": true,
197 "seed": 8675309
189198 },
190199 "sharding": {
191200 "index": 1,
@@ -204,6 +213,8 @@ limitations as their CLI equivalents; unsupported combinations fail explicitly.
204213
205214See [Retries, repeats, and flaky tests](docs/retries-and-repeats.md) for attempt
206215semantics, exit codes, reporter output, and programmatic configuration.
216See [Randomized test order](docs/randomized-order.md) for replay and ordering
217guarantees.
207218
208219### Parallel execution semantics
209220
@@ -212,7 +223,8 @@ and set `n_jobs`. A configured value is the exact maximum number of active test
212223workers; omitting it uses the host's logical CPU count, with a one-worker
213224fallback when detection is unavailable.
214225
215Suites and nested suites are visited in declaration order. `beforeAll` and
226Suites and nested suites are visited in the selected order: declaration order
227by default, or deterministic seed order when randomization is enabled. `beforeAll` and
216228`afterAll` run once on the coordinating thread around that suite and its nested
217229suites. Direct tests within a suite may overlap. Their inherited `beforeEach`
218230and `afterEach` hooks run on the same worker as the test, so per-test hook order
@@ -220,7 +232,7 @@ is preserved but hooks from different tests may overlap. Hook state and the
220232allocator passed to tests must therefore be thread-safe.
221233
222234Reporter callbacks never run concurrently: test results are emitted in
223declaration order after each parallel batch, making output and final totals
235the selected order after each parallel batch, making output and final totals
224236deterministic. A parallel batch is already scheduled as a unit, so `bail` cannot
225237cancel tests that have started.
226238
@@ -665,6 +677,8 @@ zig-test --no-color
665677| `--retry <N>` | `--retries <N>` | Retry each failed test up to N times |
666678| `--repeat <N>` | | Require N successful runs of each selected test |
667679| `--fail-on-flaky` | | Fail the run when a retry recovers a failure |
680| `--shuffle` | | Randomize suite, test, and discovered-file order |
681| `--seed <N>` | | Replay a randomized order; implies `--shuffle` |
668682| `--verbose` | | Enable verbose output |
669683| `--quiet` | `-q` | Minimal output |
670684| `--no-color` | | Disable colored output |