Skip to content

Conversation

@filosganga
Copy link

@filosganga filosganga commented Oct 16, 2025

This PR is an attempt to achieve #233.

Summary

This PR adds tag-based test filtering using GitHub's label filtering syntax with wildcard pattern matching support. Users can now filter tests by tags using the -t/--tags flag with expressive boolean logic and wildcards.

Changes

Core Implementation

  • TagExpr.scala - Tag expression AST with Atom, Wildcard, Not, And, Or nodes
  • GithubTagExprParser.scala - Parser for GitHub-style syntax (replaces PyTest-style TagExprParser)
    • , for OR operator
    • (space) for AND operator
    • ! for NOT operator
    • () for grouping
  • Wildcard pattern matching - Using cats-parse combinators
    • * matches zero or more characters
    • ? matches exactly one character
    • Support for patterns like bug-*, *-prod, first*bug, test-?
  • Filters.scala - Integration with existing filtering infrastructure

Tests

  • TagExprTests.scala - Comprehensive wildcard pattern parsing and matching tests
    • Positive tests for valid patterns
    • Negative tests for invalid patterns
    • Wildcard matching behavior tests
  • GithubTagExprParserTests.scala - Parser syntax tests with GitHub-style expressions

Documentation

  • filtering.md - Complete guide on pattern and tag-based filtering
    • Tag expression syntax and operators
    • Wildcard patterns with examples
    • Precedence rules
    • Combining pattern and tag filters
  • tagging.md - How to add tags and naming conventions
    • .tagged() method usage
    • Special tags: .ignore and .only
    • Warning about tags with spaces
  • README.md - Overview of the new tag filtering feature

Breaking Changes

  • None - this is a new feature that's fully backward compatible
  • Existing pattern filtering (-o/--only) continues to work unchanged
  • Existing test tagging (.tagged(), .ignore, .only) continues to work unchanged

Dependencies

  • Updated cats-parse from 0.3.10 to 1.0.0 (required for .soft/.backtrack APIs)

Examples

Run tests tagged as "bug" OR "feature":

testOnly -- -t "bug,feature"

Run tests tagged as both "integration" AND "database":

testOnly -- -t "integration database"

Run all tests except "slow" ones:

testOnly -- -t "!slow"

Run bug-related tests, excluding wontfix:

testOnly -- -t "bug,feature !wontfix"

Run all tests matching bug-* pattern:

testOnly -- -t "bug-*"

Run tests matching environment pattern:

testOnly -- -t "*:prod"

Complex expression with grouping:

testOnly -- -t "(bug,feature) critical !wontfix"

Combine tag and pattern filters:

testOnly -- -t "integration" -o "*database*"

Comment on lines +66 to +70
def unsafeFromPattern(pattern: String): Wildcard =
fromPattern(pattern).leftMap { e =>
new RuntimeException(
s"The pattern: ${pattern} is not a valid tag wildcard. ${e}")
}.fold(throw _, identity)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is almost only for testing purposes, we could use literally instead as, for testing, the pattern is always known at compile time

@filosganga filosganga marked this pull request as ready for review October 17, 2025 08:11
@zainab-ali
Copy link
Contributor

Thanks @filosganga ! I've added some ideas to the issue #233 (comment), suggesting that we improve support for --only instead. Let me know what you think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants