-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
libtest: add glob support to test name filters #46417
Conversation
r? @bluss (rust_highfive has picked a reviewer for you, use r? to override) |
One question that should probably be resolved: currently, globbing is enabled either if
With the tests All this taken together, I suggest we keep things the way they are currently (only infer from main pattern or presence of |
432a38b
to
6775588
Compare
Tests can currently only be filtered by substring or exact match. This makes it difficult to have finer-grained control over which tests to run, such as running only tests with a given suffix in a module, all tests without a given suffix, etc. This PR adds a `--glob` flag to make test name filters use glob patterns instead of string substring matching. This allows commands such as: --glob mymod::*_fast or --glob --skip *_slow The `--glob` flag can normally be omitted, as it is inferred whenever a pattern includes one of the glob special characters (`*`, `?`, or `[`). These characters cannot appear in ordinary test names, so this should not cause unexpected results. If both `--exact` *and* `--glob` are given, `--exact` takes precedence. Fixes rust-lang#46408.
6775588
to
9813b49
Compare
I changed my mind. Latest commit interprets patterns independently, so the example given before
will now work correctly (it'll include |
17c28f6
to
0a122f0
Compare
The filter and each skip rule are now all interpreted as test name patterns separately. This means that, unless `--glob` is passed, only patterns containing glob characters are considered glob patterns. For example: foo --skip *_slow Will consider `foo` a substring pattern, and `*_slow` a glob pattern. Similarly *_fast --skip bar Will run `foo_fast`, but not `bar_fast`.
0a122f0
to
0b83c56
Compare
This PR should probably also be tagged with |
Surprisingly tricky to figure out who the right person for review on |
Code looks good in general. However, I'm not sure why we need the Could you explain that? In terms of review, it seems like we may want to make this unstable, but I don't know if that's possible for libtest parameters. If we can't make it unstable then we should get all of libs team to sign off on it at least. |
Good point -- I removed the flag. Technically the flag changes the behaviour of strings that do not contain the special characters, since globs required a complete match. Non-glob matches are substring matches by default. But I think you're right that in practice the I don't know of a way to make libtest parameters unstable, except by manually adding |
@rust-lang/libs thoughts? This seems good but I'd want sign off from everyone since it'll probably be insta-stable. |
This seems like a fine idea in principle. I think my only concern here would be the stabilization of the glob syntax itself. Aside from the fact that the glob crate isn't extern crate glob;
use glob::Pattern;
fn main() {
let pat = Pattern::new("{*").unwrap();
println!("{:?}", pat.matches("{foo"));
let pat = Pattern::new("{foo}").unwrap();
println!("{:?}", pat.matches("{foo}"));
} Would we consider this an acceptable breaking change? If so, then I suppose it seems fine to move forward. (In the sense that I can't think of any other concerns with the public facing interface.) |
2871364
to
2482c58
Compare
@BurntSushi I'm not too concerned about that for the same reason I'm not concerned about introducing automatic interpretation of strings as globs in general: test names cannot contain |
Historically the test crate actually had support for full-blown regexes and that was just removed in the lead-up to 1.0 where we moved the regex crate to crates.io instead of in the standard library/libextra. In that sense there's definitely desire for this! That being said I'm wary of using the So I guess tl;dr; I'd ideally prefer for the extra support we add here to be specifyable (aka have documentation and be supported) which I think rules out |
I'd love having full regex support (similar to Custom test runners would be nice, I agree, but as you say we have been wanting that for a long time, and it doesn't seem like much is changing any time soon. It's also nice for the default thing that is run with I think |
Gentle ping @alexcrichton |
Ah sorry about that. I definitely understand where you're coming from but for me maintainability of a crate like libtest trumps almost all else, so the fact that |
Hmm, that's unfortunate, but I understand the reasoning. Is there any particular place to monitor the progress of custom test runners, and potentially to contribute/discuss directions going forward? |
For posterity, the conversation here was resumed on IRC |
Also relevant: https://internals.rust-lang.org/t/past-present-and-future-for-rust-testing/6354/18 Putting this in the libs team's court for triage purposes :) |
@carols10cents hehe, yes, that was the follow-up to the IRC follow-up. @steveklabnik mentioned that he wanted to bring it up during the work week, so hopefully we'll see some further discussion coming out of that. |
Ok I'm going to close this for no in favor of @jonhoo's thread on internals |
Tests can currently only be filtered by substring or exact match. This makes it difficult to have finer-grained control over which tests to run (#46408), such as running only tests with a given suffix in a module, all tests without a given suffix, etc.
This PR adds support for glob patterns in test name filters. When at least one of the special glob characters (
*
,?
, or[
) are present, the pattern is interpreted as a glob, and used to match against test names. These characters cannot appear in ordinary test names, so this should not cause unexpected results. This allows commands such as:or
Fixes #46408.