Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/libtest2/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
85 changes: 77 additions & 8 deletions crates/libtest2/tests/testsuite/should_panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down Expand Up @@ -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:

Expand All @@ -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:
Expand All @@ -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


"#]],
Expand Down