Skip to content

feat(cli): --exclude-filter to skip tests by name #1009

Description

@Chemaclass

Problem

Selection by name is one-directional. --filter <name> includes; there is no way to exclude by name. Tags have both (--tag / --exclude-tag), names do not.

The common case is "run everything except the handful of tests matching slow_network" without going back and tagging them first. bats-core ships --negative-filter <regex> for exactly this.

Proposal

--exclude-filter <name>   Skip tests whose name matches (repeatable)
  • Matching semantics identical to --filter, so the two are symmetric and predictable.
  • Repeatable; a test is skipped if it matches any --exclude-filter.
  • Exclusion wins over inclusion, mirroring how --exclude-tag beats --tag.
  • Works together with --tag, --shard, --rerun-failed.

Where to change

  • src/helper/discovery.sh:62 get_functions_to_run — the include decision is made here.
  • src/main/test.sh flag parsing, src/config/env.sh for BASHUNIT_EXCLUDE_FILTER.

Acceptance criteria

  • --exclude-filter foo runs every test except those matching foo
  • --filter user --exclude-filter admin runs user tests that are not admin tests
  • Repeated --exclude-filter flags are OR'd
  • Exclusion wins when a name matches both --filter and --exclude-filter
  • Excluded tests are not reported as skipped — they are not selected at all (same as --exclude-tag)
  • Works with file::fn and file:LINE targeting
  • Unit tests in tests/unit/helper/discovery_test.sh plus an acceptance test

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions