Why
bashunit has 8 subcommands and ~50 flags (src/main.sh options block) but no shell completion — discoverability currently requires --help round-trips. Zero completions exist in the repo today (no completions/, no compgen usage).
Proposal
- Ship static completion scripts for bash and zsh under
completions/ (completions/bashunit.bash, completions/_bashunit):
- subcommands:
test bench doc init learn upgrade assert watch (bashunit entry + src/main.sh)
- all long/short flags of the default
test subcommand, with value hints where cheap (--output tap, --jobs auto, directory/file completion for positional args and -e/--env)
bashunit assert <fn> completing the public assertion names (static list is fine)
- Document installation in the docs site (bash-completion dir, zsh
fpath) and mention in README.
- Anti-drift test: add a unit/acceptance test that extracts the flag list from the completion scripts and compares it against the flags parsed in
src/main.sh (grep the case arms or the --help output), so a new flag fails CI until completions are updated. This is the piece that keeps the static scripts honest.
Optional (separate commit, only if straightforward): bashunit completion bash|zsh subcommand that prints the script, so eval "$(bashunit completion bash)" works without knowing install paths.
Tests first (TDD)
Write the anti-drift test first (it defines the contract), then the scripts to satisfy it. Completion scripts themselves are hard to integration-test portably — the drift test plus a bash syntax check (bash -n completions/bashunit.bash) is enough.
Constraints
- Completion scripts may use Bash 4+ features only if guarded — but the core framework files stay Bash 3.0+. Prefer plain
compgen -W style that works on macOS bash 3.2.
- No new runtime dependency for the framework itself.
- CHANGELOG.md entry.
Acceptance criteria
Why
bashunit has 8 subcommands and ~50 flags (
src/main.shoptions block) but no shell completion — discoverability currently requires--helpround-trips. Zero completions exist in the repo today (nocompletions/, nocompgenusage).Proposal
completions/(completions/bashunit.bash,completions/_bashunit):test bench doc init learn upgrade assert watch(bashunitentry +src/main.sh)testsubcommand, with value hints where cheap (--output tap,--jobs auto, directory/file completion for positional args and-e/--env)bashunit assert <fn>completing the public assertion names (static list is fine)fpath) and mention in README.src/main.sh(grep thecasearms or the--helpoutput), so a new flag fails CI until completions are updated. This is the piece that keeps the static scripts honest.Optional (separate commit, only if straightforward):
bashunit completion bash|zshsubcommand that prints the script, soeval "$(bashunit completion bash)"works without knowing install paths.Tests first (TDD)
Write the anti-drift test first (it defines the contract), then the scripts to satisfy it. Completion scripts themselves are hard to integration-test portably — the drift test plus a bash syntax check (
bash -n completions/bashunit.bash) is enough.Constraints
compgen -Wstyle that works on macOS bash 3.2.Acceptance criteria
bash -npasses on the bash script; zsh script loads underzsh -fwithcompinit.src/main.shbut not to the scripts (demonstrate in PR description)../bashunit tests/,make sa,make lintpass.