Summary
Add --random-order to shuffle test execution order, plus --seed <n> (and BASHUNIT_SEED) to reproduce a given shuffle. Surfaces hidden inter-test coupling (tests that only pass because of ordering / shared state).
Motivation
Tests that pass only in declaration order hide real bugs (leaked globals, temp files, ordering deps). Randomizing order catches them; a printed seed makes a failure reproducible. Verified missing: grep -- --random-order src/*.sh → none.
Proposed API
bashunit --random-order tests/ # shuffle; prints the seed used
bashunit --random-order --seed 12345 tests/ # reproduce an exact shuffle
BASHUNIT_SEED=12345 bashunit --random-order tests/
- Default: current deterministic order.
- When
--random-order is on and no seed given, generate one and print it in the run header so a failing run can be replayed.
- Shuffle applies to the ordering of test functions (and/or files — pick file+function; document which).
Files
- Flag/env parsing:
src/globals.sh.
- Test collection/order:
src/runner.sh (where the test function list is built before execution).
- Header print of seed:
src/console_header.sh.
- Docs:
docs/command-line.md, docs/configuration.md.
- Tests:
tests/acceptance/bashunit_test.sh.
Implementation notes
- Deterministic shuffle from a seed without Bash 4 features. A portable Fisher–Yates driven by a simple LCG seeded from
--seed works on Bash 3.2; do not rely on $RANDOM alone for reproducibility unless you seed it and confirm portability. Keep the RNG in a small helper (e.g. src/math.sh) with its own unit test.
TDD steps
- RED (unit): shuffle helper with a fixed seed returns a deterministic permutation; two different seeds differ; same seed twice is identical.
- RED (acceptance):
--random-order --seed X twice produces identical run order; header prints the seed.
- GREEN: wire shuffle into runner behind the flag.
- REFACTOR: confirm no change to default (non-random) ordering.
Acceptance criteria
Constraints
- Bash 3.0+ only; portable RNG (no Bash 4 features). See
.claude/rules/bash-style.md.
- Must pass
make sa, make lint, shfmt -w ., ./bashunit tests/, ./bashunit --parallel tests/.
Summary
Add
--random-orderto shuffle test execution order, plus--seed <n>(andBASHUNIT_SEED) to reproduce a given shuffle. Surfaces hidden inter-test coupling (tests that only pass because of ordering / shared state).Motivation
Tests that pass only in declaration order hide real bugs (leaked globals, temp files, ordering deps). Randomizing order catches them; a printed seed makes a failure reproducible. Verified missing:
grep -- --random-order src/*.sh→ none.Proposed API
--random-orderis on and no seed given, generate one and print it in the run header so a failing run can be replayed.Files
src/globals.sh.src/runner.sh(where the test function list is built before execution).src/console_header.sh.docs/command-line.md,docs/configuration.md.tests/acceptance/bashunit_test.sh.Implementation notes
--seedworks on Bash 3.2; do not rely on$RANDOMalone for reproducibility unless you seed it and confirm portability. Keep the RNG in a small helper (e.g.src/math.sh) with its own unit test.TDD steps
--random-order --seed Xtwice produces identical run order; header prints the seed.Acceptance criteria
--random-order,--seed <n>,BASHUNIT_SEEDparsed.Constraints
.claude/rules/bash-style.md.make sa,make lint,shfmt -w .,./bashunit tests/,./bashunit --parallel tests/.