Skip to content

Add -m / --match flag for regex-based test name filtering#428

Merged
MatthewMckee4 merged 5 commits intomainfrom
add-match-flag-name-filtering
Feb 7, 2026
Merged

Add -m / --match flag for regex-based test name filtering#428
MatthewMckee4 merged 5 commits intomainfrom
add-match-flag-name-filtering

Conversation

@MatthewMckee4
Copy link
Member

Summary

  • Add -m / --match CLI flag that filters tests by name using regular expressions
  • Uses partial matching (regex can match anywhere in the qualified test name)
  • Multiple -m flags use OR semantics, consistent with -t tag filtering
  • Non-matching tests are skipped (not excluded), consistent with existing behavior
  • Invalid regex patterns produce clear error messages with early validation

Closes #427

Test plan

  • Unit tests for NameFilter / NameFilterSet (partial match, anchored patterns, OR semantics, invalid regex, empty set, parametrized names)
  • Integration tests: substring match, anchored regex, multiple -m flags, no matches, invalid regex error, parametrized test matching, match-all
  • All 415 tests pass (just test)
  • All pre-commit checks pass (prek run -a)
  • CLI docs regenerated (cargo run -p karva_dev generate-all)

Allow users to filter tests by name using regular expressions, enabling
patterns like `karva test -m auth` to run only tests containing "auth".
Multiple `-m` flags use OR semantics, consistent with `-t` tag filtering.
Non-matching tests are skipped rather than excluded.

Closes #427
@github-actions
Copy link

github-actions bot commented Feb 7, 2026

Project Diff Results

No changes between this PR and main.

Add 11 new integration tests covering alternation, character classes,
quantifiers, module-scoped filtering, tag+name filter combination,
case sensitivity, inline flags, and additional invalid regex cases.

Fix NameFilterError to not duplicate the regex error in the error chain.
@codspeed-hq
Copy link

codspeed-hq bot commented Feb 7, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing add-match-flag-name-filtering (9e0f28b) with main (602c87b)

Summary

✅ 1 untouched benchmark

@MatthewMckee4 MatthewMckee4 added the test-running Related to running tests with karva label Feb 7, 2026
@MatthewMckee4 MatthewMckee4 merged commit 7311e45 into main Feb 7, 2026
9 checks passed
@MatthewMckee4 MatthewMckee4 deleted the add-match-flag-name-filtering branch February 7, 2026 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test-running Related to running tests with karva

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for running tests whose names match a glob

1 participant