Skip to content

Feature Requst: Add regex support to test filters #53278

Open
@TyOverby

Description

@TyOverby
Contributor

Proposal

I'd like to filter my tests based on a more complex pattern than just substring.

The current behavior of rust tests is that when a pattern is specified, then only tests that contain that pattern as a substring are run.

cargo test -- foo will run only tests that contain the substring foo.

I propose to amend this to allow for a regex syntax.

cargo test -- /regex/ which will run tests that match the regex regex.

This is "technically" a breaking change because it's possible that people are already using filters with slashes in them, but since test names can't contain slashes these invocations would always be running 0 tests.

Misc

  • Let me know if this should be an RFC. The feature seems pretty small, but I'd understand if it should be more speced out.
  • I'd be happy to implement this if people are interested.

Activity

added
C-feature-requestCategory: A feature request, i.e: not implemented / a PR.
A-libtestArea: `#[test]` / the `test` library
on Jan 11, 2019
ririsoft

ririsoft commented on Oct 11, 2019

@ririsoft

Hello,

I came to this issue while trying to run only one test in a test suite with several tests sharing the same base name. Coming from Go I wanted to run a test with foo$ for instance.

However reading this comment on Cargo, I discovered the --exact option that perfectly suite my needs.

While I believe this feature request would be a plus, I recognize that the substring feature is enough for me so far.

kennytm

kennytm commented on Sep 24, 2020

@kennytm
Member

This is "technically" a breaking change because it's possible that people are already using filters with slashes in them,

We could make it truly backward-compatible by introducing a --regex flag like the existing --exact flag (#38181)

cargo test -Z unstable-options --regex 'foo$'

One potential issue is that this makes libtest depends on regex.

added
T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.
on Sep 24, 2020
Jasonoro

Jasonoro commented on Nov 25, 2020

@Jasonoro

This looks like useful functionality, and I would like to take a stab at trying to implement it. Using a --regex flag seems like a good idea.

@kennytm You said that making libtest depend on regex might be an issue. Do you have any idea on who to ping to find out if this is a big issue or not? The dev guide just has a TODO there, and while the regex crate is approved I'd like to get some clarification on that.

@rustbot claim

Jasonoro

Jasonoro commented on Feb 7, 2021

@Jasonoro

This is currently blocked on rust-lang/regex#476, due to the fact that regex requires std which isn't available when building libtest. See also the following zulipchat conversation.

Jasonoro

Jasonoro commented on Feb 15, 2021

@Jasonoro

Some more discussion has been started in this conversation. I'll update the issue when a conclusion has been reached.

6 remaining items

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-libtestArea: `#[test]` / the `test` libraryC-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @kennytm@futurist@RalfJung@TyOverby@estebank

        Issue actions

          Feature Requst: Add regex support to test filters · Issue #53278 · rust-lang/rust