Problem
--rerun-failed replays the last failing tests and drops everything else (src/config/rerun.sh:113 filter_functions). That is the right tool while fixing a specific failure, but it is the wrong tool for CI and for the final check before pushing, where you want the full suite — just with the known-bad tests first, so --stop-on-failure trips in seconds instead of minutes.
The failure cache that makes this possible already exists (.bashunit/last-failed, src/config/rerun.sh); nothing consumes it for ordering.
Proposal
--order-by <mode> defects | defined (default) | random
defects — tests that failed on the last recorded run execute first, in the order recorded; everything else follows in its normal order. The full suite still runs.
defined — current behaviour, named so it can be set explicitly in .bashunitrc.
random — equivalent to the existing --random-order; keep --random-order and --seed working unchanged as aliases.
With no cache file, defects degrades silently to defined.
Where to change
src/config/rerun.sh:68 load, :83 files, :96 allows — read the cache without filtering it.
src/helper/discovery.sh:208 load_test_files and :62 get_functions_to_run — ordering hook, same place --random-order applies.
src/main/test.sh, src/config/env.sh (BASHUNIT_ORDER_BY), .env.example.
Acceptance criteria
Repo checklist (agent)
- TDD: RED → GREEN → REFACTOR. Write the failing test first.
- Bash 3.0+ only: no
printf -v, no += append, no declare -A, no [[ ]], no ${var,,}, no &>>, no ${arr[-1]}. Expanding a possibly-empty array under set -u needs ${arr[@]+"${arr[@]}"}.
- A new CLI flag must be wired in all of these or a parity test fails:
- Gates:
make sa, make lint, ./bashunit tests/, ./bashunit --parallel tests/. Never run shfmt -w.
- Docs: update
docs/command-line.md. Editing docs/assertions.md invalidates the bashunit doc acceptance snapshot — regenerate it.
- CHANGELOG.md: add one line under
## Unreleased.
- Fixtures under
tests/acceptance/fixtures/ must not end in *test.sh.
- One issue = one PR.
Problem
--rerun-failedreplays the last failing tests and drops everything else (src/config/rerun.sh:113filter_functions). That is the right tool while fixing a specific failure, but it is the wrong tool for CI and for the final check before pushing, where you want the full suite — just with the known-bad tests first, so--stop-on-failuretrips in seconds instead of minutes.The failure cache that makes this possible already exists (
.bashunit/last-failed,src/config/rerun.sh); nothing consumes it for ordering.Proposal
defects— tests that failed on the last recorded run execute first, in the order recorded; everything else follows in its normal order. The full suite still runs.defined— current behaviour, named so it can be set explicitly in.bashunitrc.random— equivalent to the existing--random-order; keep--random-orderand--seedworking unchanged as aliases.With no cache file,
defectsdegrades silently todefined.Where to change
src/config/rerun.sh:68load,:83files,:96allows— read the cache without filtering it.src/helper/discovery.sh:208load_test_filesand:62get_functions_to_run— ordering hook, same place--random-orderapplies.src/main/test.sh,src/config/env.sh(BASHUNIT_ORDER_BY),.env.example.Acceptance criteria
--order-by defectsruns the full suite with previously failing tests first--order-by defects --stop-on-failurestops on the first known-bad test on a repeat run.bashunit/last-faileddegrades todefinedorder without a warning storm--order-by randombehaves identically to--random-order, and--seedstill applies--order-byand--rerun-failedtogether:--rerun-failedstill narrows the set,--order-byonly orders it--parallelin the sense that the cached failures are dispatched firsttests/unit/config/rerun_test.shplus an acceptance testRepo checklist (agent)
printf -v, no+=append, nodeclare -A, no[[ ]], no${var,,}, no&>>, no${arr[-1]}. Expanding a possibly-empty array underset -uneeds${arr[@]+"${arr[@]}"}.src/main/test.sh(report-style flags needexport -n, seesrc/main/test.sh:188-196for why)bashunit::main::validate_config_or_exit(src/main/validate.sh:60) — unvalidated input used to run the wrong thing and exit 0 (Unknown options are silently ignored: a typo'd flag runs a different suite and exits 0 #871, --jobs with a non-integer value hangs on Bash 3.x and is silently ignored on Bash 4.3+ #873)src/config/env.shand a documented line in.env.example--helptext in the same block it belongs tocompletions/bashunit.bashandcompletions/_bashunit(anti-drift test feat(cli): bash and zsh completion scripts with an anti-drift test #778 fails otherwise)make sa,make lint,./bashunit tests/,./bashunit --parallel tests/. Never runshfmt -w.docs/command-line.md. Editingdocs/assertions.mdinvalidates thebashunit docacceptance snapshot — regenerate it.## Unreleased.tests/acceptance/fixtures/must not end in*test.sh.