From d2e441a6ad2f00b6504a6b7ab174dfc258588cd3 Mon Sep 17 00:00:00 2001 From: Herman Skogseth Date: Thu, 6 Nov 2025 16:08:49 +0100 Subject: [PATCH 1/2] fix: `#[should_panic]` breaks multiple `#[ignore]` If a `#[should_panic]` was parsed before a duplicate `#[ignore]`, then the duplicate `#[ignore]` would lead to an "unknown attribute" compilation error. --- crates/libtest2/src/macros.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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) From 719a9e73695686c6051908caac58b5516da727d7 Mon Sep 17 00:00:00 2001 From: Herman Skogseth Date: Fri, 7 Nov 2025 13:23:21 +0100 Subject: [PATCH 2/2] fix: Add test for mix of should_panic and ignore --- .../libtest2/tests/testsuite/should_panic.rs | 85 +++++++++++++++++-- 1 file changed, 77 insertions(+), 8 deletions(-) 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 "#]],