Skip to content

feat(cli): bash and zsh completion scripts with an anti-drift test #778

Description

@Chemaclass

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

  1. 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)
  2. Document installation in the docs site (bash-completion dir, zsh fpath) and mention in README.
  3. 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

  • bash -n passes on the bash script; zsh script loads under zsh -f with compinit.
  • Drift test fails when a flag is added to src/main.sh but not to the scripts (demonstrate in PR description).
  • Docs updated with install instructions.
  • ./bashunit tests/, make sa, make lint pass.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions