Skip to content

feat(tags): tag expressions (AND / NOT) and file-level @tags #1008

Description

@Chemaclass

Problem

Tag selection is weaker than the systems people migrate from.

  • --tag is repeatable but OR-only (bashunit test --help: "repeatable, OR logic"). There is no way to say "slow and db".
  • There is no negation inside an expression; --exclude-tag is a separate flag that always wins.
  • Tags are per function only. src/helper/tags.sh:10 build_tags_map scans the contiguous comment block directly above each function definition, so tagging a whole file means repeating # @tag integration above every test in it.

bats-core supports --filter-tags 'a,!b' with AND semantics and has both # bats test_tags= and # bats file_tags=.

Proposal

File-level tags — a # @tags <list> comment before the first function definition (or anywhere at top level) applies to every test in that file, unioned with per-function # @tag.

Tag expressions in --tag:

--tag slow              # has slow                     (unchanged)
--tag slow --tag db     # slow OR db                   (unchanged, back-compat)
--tag 'slow&&db'        # slow AND db
--tag '!slow'           # NOT slow
--tag 'db&&!slow'       # db AND NOT slow

Precedence stays as documented: --exclude-tag still wins over any --tag match.

Where to change

  • src/helper/tags.sh:10 build_tags_map — single awk pass; extend it to also collect file-level tags and union them in.
  • src/helper/tags.sh:99 function_matches_tags — the expression evaluator lives here.
  • src/helper/tags.sh:74 tags_for_function.

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.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions