Skip to content

Commit fc69714

Browse files
Add regression test for #143009
1 parent 3811364 commit fc69714

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Ensure that `should_panic` doctests only succeed if the test actually panicked.
2+
// Regression test for <https://github.com/rust-lang/rust/issues/143009>.
3+
4+
//@ needs-target-std
5+
6+
use run_make_support::rustdoc;
7+
8+
fn check_output(output: String, edition: &str) {
9+
let should_contain = &[
10+
"test test.rs - bad_exit_code (line 1) ... FAILED",
11+
"test test.rs - did_not_panic (line 6) ... FAILED",
12+
"test test.rs - did_panic (line 11) ... ok",
13+
"---- test.rs - bad_exit_code (line 1) stdout ----
14+
Test executable failed (exit status: 1).",
15+
"---- test.rs - did_not_panic (line 6) stdout ----
16+
Test didn't panic, but it's marked `should_panic`.",
17+
"test result: FAILED. 1 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out;",
18+
];
19+
for text in should_contain {
20+
assert!(
21+
output.contains(text),
22+
"output doesn't contains (edition: {edition}) {:?}\nfull output: {output}",
23+
text
24+
);
25+
}
26+
}
27+
28+
fn main() {
29+
check_output(rustdoc().input("test.rs").arg("--test").run_fail().stdout_utf8(), "2015");
30+
31+
// Same check with the merged doctest feature (enabled with the 2024 edition).
32+
check_output(
33+
rustdoc().input("test.rs").arg("--test").edition("2024").run_fail().stdout_utf8(),
34+
"2024",
35+
);
36+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// ```
2+
/// std::process::exit(1);
3+
/// ```
4+
fn bad_exit_code() {}
5+
6+
/// ```should_panic
7+
/// std::process::exit(1);
8+
/// ```
9+
fn did_not_panic() {}
10+
11+
/// ```should_panic
12+
/// panic!("yeay");
13+
/// ```
14+
fn did_panic() {}

0 commit comments

Comments
 (0)