diff --git a/crates/libtest2/src/macros.rs b/crates/libtest2/src/macros.rs index f813d92..50c249c 100644 --- a/crates/libtest2/src/macros.rs +++ b/crates/libtest2/src/macros.rs @@ -47,12 +47,13 @@ macro_rules! _test_parse { ); }; // Ignore subsequent calls to `#[ignore]`/`#[ignore = ".."]` - (continue: name=$name:ident body=[$($item:tt)*] attrs=[#[ignore $(= $reason:literal)?] $(#[$($attr:tt)+])*] ignore=$ignore:tt) => { + (continue: name=$name:ident body=[$($item:tt)*] attrs=[#[ignore $(= $reason:literal)?] $(#[$($attr:tt)+])*] ignore=$ignore:tt $(should_panic=$should_panic:tt)?) => { $crate::_private::test_parse!(continue: name=$name body=[$($item)*] attrs=[$(#[$($attr)*])*] ignore=$ignore + $(should_panic=$should_panic)? ); }; // Process `#[should_panic]`/`#[should_panic = ".."]` (NOTE: This will only match if a should_panic macro has not already been parsed) diff --git a/crates/libtest2/tests/testsuite/should_panic.rs b/crates/libtest2/tests/testsuite/should_panic.rs index c56b017..0828a65 100644 --- a/crates/libtest2/tests/testsuite/should_panic.rs +++ b/crates/libtest2/tests/testsuite/should_panic.rs @@ -32,6 +32,14 @@ fn intentionally_panics_with_message(_context: &libtest2::TestContext) { fn panics_with_the_wrong_message(_context: &libtest2::TestContext) { panic!("with the wrong message") } + +#[libtest2::test] +#[ignore] +#[should_panic] +#[ignore = "this attribute should just be skipped"] +fn intentionally_panics_but_is_usually_ignored(_context: &libtest2::TestContext) { + panic!("whatever") +} "#, false, ); @@ -62,11 +70,72 @@ fn normal() { 101, str![[r#" -running 4 tests -test accidentally_panics ... FAILED -test intentionally_panics ... ok -test intentionally_panics_with_message ... ok -test panics_with_the_wrong_message ... FAILED +running 5 tests +test accidentally_panics ... FAILED +test intentionally_panics ... ok +test intentionally_panics_but_is_usually_ignored ... ignored +test intentionally_panics_with_message ... ok +test panics_with_the_wrong_message ... FAILED + +failures: + +---- accidentally_panics ---- +test panicked: uh oh + +---- panics_with_the_wrong_message ---- +panic did not contain expected string + panic message: "with the wrong message" + expected substring: "in a controlled manner" + + +failures: + accidentally_panics + panics_with_the_wrong_message + +test result: FAILED. 2 passed; 2 failed; 1 ignored; 0 filtered out; finished in [..]s + + +"#]], + str![[r#" + +running 5 tests +... + +failures: + +---- accidentally_panics ---- +test panicked: uh oh + +---- panics_with_the_wrong_message ---- +panic did not contain expected string + panic message: "with the wrong message" + expected substring: "in a controlled manner" + + +failures: + accidentally_panics + panics_with_the_wrong_message + +test result: FAILED. 2 passed; 2 failed; 1 ignored; 0 filtered out; finished in [..]s + + +"#]], + ); +} + +#[test] +fn include_ignored_normal() { + check( + &["--include-ignored"], + 101, + str![[r#" + +running 5 tests +test accidentally_panics ... FAILED +test intentionally_panics ... ok +test intentionally_panics_but_is_usually_ignored ... ok +test intentionally_panics_with_message ... ok +test panics_with_the_wrong_message ... FAILED failures: @@ -83,13 +152,13 @@ failures: accidentally_panics panics_with_the_wrong_message -test result: FAILED. 2 passed; 2 failed; 0 ignored; 0 filtered out; finished in [..]s +test result: FAILED. 3 passed; 2 failed; 0 ignored; 0 filtered out; finished in [..]s "#]], str![[r#" -running 4 tests +running 5 tests ... failures: @@ -107,7 +176,7 @@ failures: accidentally_panics panics_with_the_wrong_message -test result: FAILED. 2 passed; 2 failed; 0 ignored; 0 filtered out; finished in [..]s +test result: FAILED. 3 passed; 2 failed; 0 ignored; 0 filtered out; finished in [..]s "#]],