feat(tags): tag expressions (AND / NOT) and file-level @tags - #1035
Merged
Conversation
--tag was OR-only with no negation, and tags were per-function only, so tagging a whole file meant repeating `# @tag` above every test. `# @tags a b` now applies to every test in the file, unioned with per-function `# @tag` and deduplicated. It is collected in the same single awk pass, buffered to END so a `# @tags` line below the functions still applies to them. A single --tag value accepts `a&&b` and `!a`, combinable as `a&&!b`. Repeated --tag flags arrive comma-joined and keep OR semantics between expressions, so existing usage is unchanged, and --exclude-tag still wins. `!a` matches untagged tests, which required dropping the early "no tags means no match" short-circuit. A malformed expression is rejected at parse time with a non-zero exit. The trailing-separator case is the one that mattered: `a&&` reads as valid and used to evaluate as plain `a`, because consuming the separator emptied the remainder and ended the loop before the empty term was checked. Closes #1008
This was referenced Aug 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤔 Background
Related #1008
Tag selection was weaker than the systems people migrate from:
--tagwas OR-only with no negation, and tags were per-function only — tagging a whole file meant repeating# @tagabove every test.💡 Changes
# @tags a bapplies to every test in the file, unioned with per-function# @tagand deduplicated. Collected in the same single awk pass and buffered toEND, so a# @tagsline placed below the functions still applies to them--tagacceptsa&&b(AND) and!a(NOT), combinable asa&&!b.!amatches untagged tests, which meant dropping the early "no tags means no match" short-circuit--tagflags keep OR semantics between expressions (no behaviour change for existing users), and--exclude-tagstill winsThe bug worth calling out
--tag 'slow&&'reads as valid and used to silently evaluate as plainslow: consuming the&&emptied the remainder, so thewhile [ -n "$rest" ]loop ended before the empty trailing term was ever checked. Both the evaluator and the validator now always consume one term per iteration and stop only after the last, so the empty term surfaces. The test that first covered this only used'&&', which was caught — a separate case now pins the trailing form.Verification
Mutation-tested: ignoring negation fails 7 tests, turning AND into OR fails 16, dropping file tags fails 6. Green on the Bash 3.2 floor. Tags containing spaces (
# @tag needs db) still select and negate correctly.Selection is asserted through
--list(#1007) rather than by parsing run output.