Skip to content

Commit 7bed27f

Browse files
authored
Rollup merge of rust-lang#139328 - GuillaumeGomez:fix-panic-output-137970, r=fmease
Fix 2024 edition doctest panic output Fixes rust-lang#137970. The problem was that the output was actually displayed by rustc itself because we're exiting with `Result<(), String>`, and the display is really not great. So instead, we get the output, we print it and then we return an `ExitCode`. r? ``@aDotInTheVoid``
2 parents 676950e + f9927ee commit 7bed27f

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

src/librustdoc/doctest/runner.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ impl DocTestRunner {
113113
mod __doctest_mod {{
114114
use std::sync::OnceLock;
115115
use std::path::PathBuf;
116+
use std::process::ExitCode;
116117
117118
pub static BINARY_PATH: OnceLock<PathBuf> = OnceLock::new();
118119
pub const RUN_OPTION: &str = \"RUSTDOC_DOCTEST_RUN_NB_TEST\";
@@ -123,16 +124,17 @@ mod __doctest_mod {{
123124
}}
124125
125126
#[allow(unused)]
126-
pub fn doctest_runner(bin: &std::path::Path, test_nb: usize) -> Result<(), String> {{
127+
pub fn doctest_runner(bin: &std::path::Path, test_nb: usize) -> ExitCode {{
127128
let out = std::process::Command::new(bin)
128129
.env(self::RUN_OPTION, test_nb.to_string())
129130
.args(std::env::args().skip(1).collect::<Vec<_>>())
130131
.output()
131132
.expect(\"failed to run command\");
132133
if !out.status.success() {{
133-
Err(String::from_utf8_lossy(&out.stderr).to_string())
134+
eprint!(\"{{}}\", String::from_utf8_lossy(&out.stderr));
135+
ExitCode::FAILURE
134136
}} else {{
135-
Ok(())
137+
ExitCode::SUCCESS
136138
}}
137139
}}
138140
}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// This is a regression test for <https://github.com/rust-lang/rust/issues/137970>.
2+
// The output must look nice and not like a `Debug` display of a `String`.
3+
4+
//@ edition: 2024
5+
//@ compile-flags: --test
6+
//@ normalize-stdout: "tests/rustdoc-ui/doctest" -> "$$DIR"
7+
//@ normalize-stdout: "panicked at .+rs:" -> "panicked at $$TMP:"
8+
//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME"
9+
//@ rustc-env:RUST_BACKTRACE=0
10+
//@ failure-status: 101
11+
12+
//! ```rust
13+
//! assert_eq!(2 + 2, 5);
14+
//! ```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
running 1 test
3+
test $DIR/edition-2024-error-output.rs - (line 12) ... FAILED
4+
5+
failures:
6+
7+
---- $DIR/edition-2024-error-output.rs - (line 12) stdout ----
8+
9+
thread 'main' panicked at $TMP:6:1:
10+
assertion `left == right` failed
11+
left: 4
12+
right: 5
13+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
14+
15+
16+
failures:
17+
$DIR/edition-2024-error-output.rs - (line 12)
18+
19+
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
20+

0 commit comments

Comments
 (0)