Skip to content

Commit 233f8ad

Browse files
authored
fix: #[should_panic] breaks multiple #[ignore] (#158)
An edge case I came across. Sidenote: Should probably move to a more robust system that avoids these edge cases, particularly as the number of macros increases.
2 parents f215af6 + 719a9e7 commit 233f8ad

File tree

2 files changed

+79
-9
lines changed

2 files changed

+79
-9
lines changed

crates/libtest2/src/macros.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,13 @@ macro_rules! _test_parse {
4949
);
5050
};
5151
// Ignore subsequent calls to `#[ignore]`/`#[ignore = ".."]`
52-
(continue: name=$name:ident body=[$($item:tt)*] attrs=[#[ignore $(= $reason:literal)?] $(#[$($attr:tt)+])*] ignore=$ignore:tt) => {
52+
(continue: name=$name:ident body=[$($item:tt)*] attrs=[#[ignore $(= $reason:literal)?] $(#[$($attr:tt)+])*] ignore=$ignore:tt $(should_panic=$should_panic:tt)?) => {
5353
$crate::_private::test_parse!(continue:
5454
name=$name
5555
body=[$($item)*]
5656
attrs=[$(#[$($attr)*])*]
5757
ignore=$ignore
58+
$(should_panic=$should_panic)?
5859
);
5960
};
6061
// Process `#[should_panic]`/`#[should_panic = ".."]` (NOTE: This will only match if a should_panic macro has not already been parsed)

crates/libtest2/tests/testsuite/should_panic.rs

Lines changed: 77 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ fn intentionally_panics_with_message(_context: &libtest2::TestContext) {
3232
fn panics_with_the_wrong_message(_context: &libtest2::TestContext) {
3333
panic!("with the wrong message")
3434
}
35+
36+
#[libtest2::test]
37+
#[ignore]
38+
#[should_panic]
39+
#[ignore = "this attribute should just be skipped"]
40+
fn intentionally_panics_but_is_usually_ignored(_context: &libtest2::TestContext) {
41+
panic!("whatever")
42+
}
3543
"#,
3644
false,
3745
);
@@ -62,11 +70,72 @@ fn normal() {
6270
101,
6371
str![[r#"
6472
65-
running 4 tests
66-
test accidentally_panics ... FAILED
67-
test intentionally_panics ... ok
68-
test intentionally_panics_with_message ... ok
69-
test panics_with_the_wrong_message ... FAILED
73+
running 5 tests
74+
test accidentally_panics ... FAILED
75+
test intentionally_panics ... ok
76+
test intentionally_panics_but_is_usually_ignored ... ignored
77+
test intentionally_panics_with_message ... ok
78+
test panics_with_the_wrong_message ... FAILED
79+
80+
failures:
81+
82+
---- accidentally_panics ----
83+
test panicked: uh oh
84+
85+
---- panics_with_the_wrong_message ----
86+
panic did not contain expected string
87+
panic message: "with the wrong message"
88+
expected substring: "in a controlled manner"
89+
90+
91+
failures:
92+
accidentally_panics
93+
panics_with_the_wrong_message
94+
95+
test result: FAILED. 2 passed; 2 failed; 1 ignored; 0 filtered out; finished in [..]s
96+
97+
98+
"#]],
99+
str![[r#"
100+
101+
running 5 tests
102+
...
103+
104+
failures:
105+
106+
---- accidentally_panics ----
107+
test panicked: uh oh
108+
109+
---- panics_with_the_wrong_message ----
110+
panic did not contain expected string
111+
panic message: "with the wrong message"
112+
expected substring: "in a controlled manner"
113+
114+
115+
failures:
116+
accidentally_panics
117+
panics_with_the_wrong_message
118+
119+
test result: FAILED. 2 passed; 2 failed; 1 ignored; 0 filtered out; finished in [..]s
120+
121+
122+
"#]],
123+
);
124+
}
125+
126+
#[test]
127+
fn include_ignored_normal() {
128+
check(
129+
&["--include-ignored"],
130+
101,
131+
str![[r#"
132+
133+
running 5 tests
134+
test accidentally_panics ... FAILED
135+
test intentionally_panics ... ok
136+
test intentionally_panics_but_is_usually_ignored ... ok
137+
test intentionally_panics_with_message ... ok
138+
test panics_with_the_wrong_message ... FAILED
70139
71140
failures:
72141
@@ -83,13 +152,13 @@ failures:
83152
accidentally_panics
84153
panics_with_the_wrong_message
85154
86-
test result: FAILED. 2 passed; 2 failed; 0 ignored; 0 filtered out; finished in [..]s
155+
test result: FAILED. 3 passed; 2 failed; 0 ignored; 0 filtered out; finished in [..]s
87156
88157
89158
"#]],
90159
str![[r#"
91160
92-
running 4 tests
161+
running 5 tests
93162
...
94163
95164
failures:
@@ -107,7 +176,7 @@ failures:
107176
accidentally_panics
108177
panics_with_the_wrong_message
109178
110-
test result: FAILED. 2 passed; 2 failed; 0 ignored; 0 filtered out; finished in [..]s
179+
test result: FAILED. 3 passed; 2 failed; 0 ignored; 0 filtered out; finished in [..]s
111180
112181
113182
"#]],

0 commit comments

Comments
 (0)