Skip to content

Commit b01cc9f

Browse files
authored
Rollup merge of rust-lang#81356 - ehuss:libtest-filters, r=m-ou-se
libtest: allow multiple filters Libtest ignores any filters after the first. This changes it so that if multiple filters are passed, it will test against all of them. This also affects compiletest to do the same. Closes rust-lang#30422
2 parents a4c75a7 + 1776807 commit b01cc9f

File tree

3 files changed

+34
-22
lines changed

3 files changed

+34
-22
lines changed

test/src/cli.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use super::time::TestTimeOptions;
1010
#[derive(Debug)]
1111
pub struct TestOpts {
1212
pub list: bool,
13-
pub filter: Option<String>,
13+
pub filters: Vec<String>,
1414
pub filter_exact: bool,
1515
pub force_run_in_process: bool,
1616
pub exclude_should_panic: bool,
@@ -148,12 +148,13 @@ fn optgroups() -> getopts::Options {
148148
}
149149

150150
fn usage(binary: &str, options: &getopts::Options) {
151-
let message = format!("Usage: {} [OPTIONS] [FILTER]", binary);
151+
let message = format!("Usage: {} [OPTIONS] [FILTERS...]", binary);
152152
println!(
153153
r#"{usage}
154154
155155
The FILTER string is tested against the name of all tests, and only those
156-
tests whose names contain the filter are run.
156+
tests whose names contain the filter are run. Multiple filter strings may
157+
be passed, which will run all tests matching any of the filters.
157158
158159
By default, all tests are run in parallel. This can be altered with the
159160
--test-threads flag or the RUST_TEST_THREADS environment variable when running
@@ -243,7 +244,7 @@ fn parse_opts_impl(matches: getopts::Matches) -> OptRes {
243244

244245
let logfile = get_log_file(&matches)?;
245246
let run_ignored = get_run_ignored(&matches, include_ignored)?;
246-
let filter = get_filter(&matches)?;
247+
let filters = matches.free.clone();
247248
let nocapture = get_nocapture(&matches)?;
248249
let test_threads = get_test_threads(&matches)?;
249250
let color = get_color_config(&matches)?;
@@ -253,7 +254,7 @@ fn parse_opts_impl(matches: getopts::Matches) -> OptRes {
253254

254255
let test_opts = TestOpts {
255256
list,
256-
filter,
257+
filters,
257258
filter_exact: exact,
258259
force_run_in_process,
259260
exclude_should_panic,
@@ -397,12 +398,6 @@ fn get_run_ignored(matches: &getopts::Matches, include_ignored: bool) -> OptPart
397398
Ok(run_ignored)
398399
}
399400

400-
fn get_filter(matches: &getopts::Matches) -> OptPartRes<Option<String>> {
401-
let filter = if !matches.free.is_empty() { Some(matches.free[0].clone()) } else { None };
402-
403-
Ok(filter)
404-
}
405-
406401
fn get_allow_unstable(matches: &getopts::Matches) -> OptPartRes<bool> {
407402
let mut allow_unstable = false;
408403

test/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,8 @@ pub fn filter_tests(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> Vec<TestDescA
396396
};
397397

398398
// Remove tests that don't match the test filter
399-
if let Some(ref filter) = opts.filter {
400-
filtered.retain(|test| matches_filter(test, filter));
399+
if !opts.filters.is_empty() {
400+
filtered.retain(|test| opts.filters.iter().any(|filter| matches_filter(test, filter)));
401401
}
402402

403403
// Skip tests that match any of the skip filters

test/src/tests.rs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl TestOpts {
3434
fn new() -> TestOpts {
3535
TestOpts {
3636
list: false,
37-
filter: None,
37+
filters: vec![],
3838
filter_exact: false,
3939
force_run_in_process: false,
4040
exclude_should_panic: false,
@@ -473,43 +473,60 @@ pub fn exact_filter_match() {
473473
}
474474

475475
let substr =
476-
filter_tests(&TestOpts { filter: Some("base".into()), ..TestOpts::new() }, tests());
476+
filter_tests(&TestOpts { filters: vec!["base".into()], ..TestOpts::new() }, tests());
477477
assert_eq!(substr.len(), 4);
478478

479-
let substr = filter_tests(&TestOpts { filter: Some("bas".into()), ..TestOpts::new() }, tests());
479+
let substr =
480+
filter_tests(&TestOpts { filters: vec!["bas".into()], ..TestOpts::new() }, tests());
480481
assert_eq!(substr.len(), 4);
481482

482483
let substr =
483-
filter_tests(&TestOpts { filter: Some("::test".into()), ..TestOpts::new() }, tests());
484+
filter_tests(&TestOpts { filters: vec!["::test".into()], ..TestOpts::new() }, tests());
484485
assert_eq!(substr.len(), 3);
485486

486487
let substr =
487-
filter_tests(&TestOpts { filter: Some("base::test".into()), ..TestOpts::new() }, tests());
488+
filter_tests(&TestOpts { filters: vec!["base::test".into()], ..TestOpts::new() }, tests());
488489
assert_eq!(substr.len(), 3);
489490

491+
let substr = filter_tests(
492+
&TestOpts { filters: vec!["test1".into(), "test2".into()], ..TestOpts::new() },
493+
tests(),
494+
);
495+
assert_eq!(substr.len(), 2);
496+
490497
let exact = filter_tests(
491-
&TestOpts { filter: Some("base".into()), filter_exact: true, ..TestOpts::new() },
498+
&TestOpts { filters: vec!["base".into()], filter_exact: true, ..TestOpts::new() },
492499
tests(),
493500
);
494501
assert_eq!(exact.len(), 1);
495502

496503
let exact = filter_tests(
497-
&TestOpts { filter: Some("bas".into()), filter_exact: true, ..TestOpts::new() },
504+
&TestOpts { filters: vec!["bas".into()], filter_exact: true, ..TestOpts::new() },
498505
tests(),
499506
);
500507
assert_eq!(exact.len(), 0);
501508

502509
let exact = filter_tests(
503-
&TestOpts { filter: Some("::test".into()), filter_exact: true, ..TestOpts::new() },
510+
&TestOpts { filters: vec!["::test".into()], filter_exact: true, ..TestOpts::new() },
504511
tests(),
505512
);
506513
assert_eq!(exact.len(), 0);
507514

508515
let exact = filter_tests(
509-
&TestOpts { filter: Some("base::test".into()), filter_exact: true, ..TestOpts::new() },
516+
&TestOpts { filters: vec!["base::test".into()], filter_exact: true, ..TestOpts::new() },
510517
tests(),
511518
);
512519
assert_eq!(exact.len(), 1);
520+
521+
let exact = filter_tests(
522+
&TestOpts {
523+
filters: vec!["base".into(), "base::test".into()],
524+
filter_exact: true,
525+
..TestOpts::new()
526+
},
527+
tests(),
528+
);
529+
assert_eq!(exact.len(), 2);
513530
}
514531

515532
#[test]

0 commit comments

Comments
 (0)