From 5d1f100988c12dabf5a34854e9db6875b999e357 Mon Sep 17 00:00:00 2001 From: memoryruins Date: Sat, 23 Feb 2019 21:07:04 -0500 Subject: [PATCH 1/2] Add unstable option to ignore should_panic tests. --- src/libtest/lib.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 5c7fb1b804461..a712d4092308b 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -366,6 +366,7 @@ pub struct TestOpts { pub list: bool, pub filter: Option, pub filter_exact: bool, + pub exclude_should_panic: bool, pub run_ignored: RunIgnored, pub run_tests: bool, pub bench_benchmarks: bool, @@ -385,6 +386,7 @@ impl TestOpts { list: false, filter: None, filter_exact: false, + exclude_should_panic: false, run_ignored: RunIgnored::No, run_tests: false, bench_benchmarks: false, @@ -406,6 +408,7 @@ fn optgroups() -> getopts::Options { let mut opts = getopts::Options::new(); opts.optflag("", "include-ignored", "Run ignored and not ignored tests") .optflag("", "ignored", "Run only ignored tests") + .optflag("", "exclude-should-panic", "Sets #[should_panic] tests to imply #[ignore]") .optflag("", "test", "Run tests and not benchmarks") .optflag("", "bench", "Run benchmarks instead of tests") .optflag("", "list", "List all tests and benchmarks") @@ -558,6 +561,13 @@ pub fn parse_opts(args: &[String]) -> Option { None }; + let exclude_should_panic = matches.opt_present("exclude-should-panic"); + if !allow_unstable && exclude_should_panic { + return Some(Err( + "The \"exclude-should-panic\" flag is only accepted on the nightly compiler".into(), + )); + } + let include_ignored = matches.opt_present("include-ignored"); if !allow_unstable && include_ignored { return Some(Err( @@ -648,6 +658,7 @@ pub fn parse_opts(args: &[String]) -> Option { list, filter, filter_exact: exact, + exclude_should_panic, run_ignored, run_tests, bench_benchmarks, @@ -1365,6 +1376,14 @@ pub fn filter_tests(opts: &TestOpts, tests: Vec) -> Vec { @@ -1983,6 +2002,32 @@ mod tests { assert!(!filtered[1].desc.ignore); } + #[test] + pub fn exclude_should_panic_option() { + let mut opts = TestOpts::new(); + opts.run_tests = true; + opts.exclude_should_panic = true; + + let mut tests = one_ignored_one_unignored_test(); + + tests.push(TestDescAndFn { + desc: TestDesc { + name: StaticTestName("3"), + ignore: false, + should_panic: ShouldPanic::YesWithMessage("should panic with message"), + allow_fail: false, + }, + testfn: DynTestFn(Box::new(move || {})), + }); + + let filtered = filter_tests(&opts, tests); + + assert_eq!(filtered.len(), 3); + assert!(filtered[0].desc.ignore); + assert!(!filtered[1].desc.ignore); + assert!(filtered[2].desc.ignore); + } + #[test] pub fn exact_filter_match() { fn tests() -> Vec { From 43e7434120a10f86713091667258f58b6c245e2d Mon Sep 17 00:00:00 2001 From: memoryruins Date: Sun, 24 Feb 2019 11:58:08 -0500 Subject: [PATCH 2/2] Simplify exclude_should_panic flag. --- src/libtest/lib.rs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index a712d4092308b..ea821a1d9392c 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -408,7 +408,7 @@ fn optgroups() -> getopts::Options { let mut opts = getopts::Options::new(); opts.optflag("", "include-ignored", "Run ignored and not ignored tests") .optflag("", "ignored", "Run only ignored tests") - .optflag("", "exclude-should-panic", "Sets #[should_panic] tests to imply #[ignore]") + .optflag("", "exclude-should-panic", "Excludes tests marked as should_panic") .optflag("", "test", "Run tests and not benchmarks") .optflag("", "bench", "Run benchmarks instead of tests") .optflag("", "list", "List all tests and benchmarks") @@ -1376,12 +1376,9 @@ pub fn filter_tests(opts: &TestOpts, tests: Vec) -> Vec