Skip to content

Add filterset DSL for test selection#663

Merged
MatthewMckee4 merged 5 commits intomainfrom
filterset-dsl
Apr 11, 2026
Merged

Add filterset DSL for test selection#663
MatthewMckee4 merged 5 commits intomainfrom
filterset-dsl

Conversation

@MatthewMckee4
Copy link
Copy Markdown
Member

@MatthewMckee4 MatthewMckee4 commented Apr 11, 2026

Summary

Closes #546.

Replaces -t/--tag and -m/--match with one flag, -E/--filter, that takes an expression language like nextest's filtersets.

karva test -E 'tag(slow)'
karva test -E 'test(/^auth::/) & not tag(flaky)'
karva test -E '(tag(fast) | tag(unit)) - tag(flaky)'

Two predicates: test(...) against the qualified test name, tag(...) against custom tags. Four matcher kinds — =exact, ~substring, /regex/, #glob — with test() defaulting to substring and tag() defaulting to exact. Operators are &, |, not, and - (and-not), with parens for grouping. Keyword spellings and/or/not also work. Multiple -E flags OR together like -t/-m used to.

Old → new:

  • -t slow-E 'tag(slow)'
  • -m auth-E 'test(/auth/)'
  • -t slow -m auth-E 'tag(slow) & test(/auth/)'
  • -t '(slow or fast) and not flaky'-E '(tag(slow) | tag(fast)) - tag(flaky)'

The full table is in docs/usage/filtering.md.

This is a breaking change — -t and -m are gone, not deprecated, per the issue thread.

The parser is in crates/karva_metadata/src/filter.rs, extending the old tag expression parser. Only new dep is globset. Filter application in package_runner::should_skip_variant is now one call instead of two. CLI parse errors get wrapped so you see which flag failed before the detailed reason.

All filter integration tests moved into crates/karva/tests/it/filterset.rs; name_filter.rs is deleted and the filter tests in extensions/tags/custom.rs and parametrize.rs moved over. Tag mechanics tests stay where they were.

Test plan

just test passes and uvx prek run -a is clean.

Replaces `-t`/`--tag` and `-m`/`--match` with a single `-E`/`--filter`
expression language inspired by nextest's filtersets: predicates
`test(<matcher>)` and `tag(<matcher>)` combined with `&`, `|`, `not`,
`-`, and parentheses, with `=exact`, `~substring`, `/regex/`, and `#glob`
matcher modes.

Closes #546.
@MatthewMckee4 MatthewMckee4 added discovery Related to the discovery of tests cli Related to the command-line interface labels Apr 11, 2026
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 11, 2026

Merging this PR will not alter performance

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

✅ 1 untouched benchmark


Comparing filterset-dsl (2a84e2e) with main (405a0c3)

Open in CodSpeed

@MatthewMckee4 MatthewMckee4 merged commit d862cc1 into main Apr 11, 2026
11 checks passed
@MatthewMckee4 MatthewMckee4 deleted the filterset-dsl branch April 11, 2026 09:49
@OmChillure
Copy link
Copy Markdown

OmChillure commented Apr 12, 2026

hey @MatthewMckee4

Now that the filterset DSL (-E/--filter) has been merged in #663, issue #549 seems to be covered without a dedicated skip()

karva test -E 'not test(~slow_)'
karva test -E 'not test(~integration_)'
karva test -E 'not test(~slow_) & not test(~integration_)'

I can see the issue #549 was marked as resolved, or would it be worth adding a dedicated skip(pattern) shorthand predicate to the DSL (e.g. -E 'skip(~slow_)' right? this will a better choice but your call !!

Thank you

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

Labels

cli Related to the command-line interface discovery Related to the discovery of tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Filterset DSL for composable test selection

2 participants