|
| 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 | +//@ ignore-cross-compile |
| 5 | + |
| 6 | +use run_make_support::rustdoc; |
| 7 | + |
| 8 | +fn check_output(edition: &str, panic_abort: bool) { |
| 9 | + let mut rustdoc_cmd = rustdoc(); |
| 10 | + rustdoc_cmd.input("test.rs").arg("--test").edition(edition); |
| 11 | + if panic_abort { |
| 12 | + rustdoc_cmd.args(["-C", "panic=abort"]); |
| 13 | + } |
| 14 | + let output = rustdoc_cmd.run_fail().stdout_utf8(); |
| 15 | + let should_contain = &[ |
| 16 | + "test test.rs - bad_exit_code (line 1) ... FAILED", |
| 17 | + "test test.rs - did_not_panic (line 6) ... FAILED", |
| 18 | + "test test.rs - did_panic (line 11) ... ok", |
| 19 | + "---- test.rs - bad_exit_code (line 1) stdout ---- |
| 20 | +Test executable failed (exit status: 1).", |
| 21 | + "---- test.rs - did_not_panic (line 6) stdout ---- |
| 22 | +Test didn't panic, but it's marked `should_panic` (got unexpected return code 1).", |
| 23 | + "test result: FAILED. 1 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out;", |
| 24 | + ]; |
| 25 | + for text in should_contain { |
| 26 | + assert!( |
| 27 | + output.contains(text), |
| 28 | + "output (edition: {edition}) doesn't contain {:?}\nfull output: {output}", |
| 29 | + text |
| 30 | + ); |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +fn main() { |
| 35 | + check_output("2015", false); |
| 36 | + |
| 37 | + // Same check with the merged doctest feature (enabled with the 2024 edition). |
| 38 | + check_output("2024", false); |
| 39 | + |
| 40 | + // Checking that `-C panic=abort` is working too. |
| 41 | + check_output("2015", true); |
| 42 | + check_output("2024", true); |
| 43 | +} |
0 commit comments