diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-04-04 21:54:57 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-04 21:54:57 +0200 |
| commit | cfc2297cfc8b8cf105c55442af8164aa759aa568 (patch) | |
| tree | 187a18ee0e1ed169d407c902e1d21e03486a472a | |
| parent | 00f608af18098e35135d79e907565c8d310dbce1 (diff) | |
| parent | f9927ee042f7d7418fbb64082272ce1feff4d895 (diff) | |
| download | rust-cfc2297cfc8b8cf105c55442af8164aa759aa568.tar.gz rust-cfc2297cfc8b8cf105c55442af8164aa759aa568.zip | |
Rollup merge of #139328 - GuillaumeGomez:fix-panic-output-137970, r=fmease
Fix 2024 edition doctest panic output Fixes #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````
| -rw-r--r-- | src/librustdoc/doctest/runner.rs | 8 | ||||
| -rw-r--r-- | tests/rustdoc-ui/doctest/edition-2024-error-output.rs | 14 | ||||
| -rw-r--r-- | tests/rustdoc-ui/doctest/edition-2024-error-output.stdout | 20 |
3 files changed, 39 insertions, 3 deletions
diff --git a/src/librustdoc/doctest/runner.rs b/src/librustdoc/doctest/runner.rs index e34b8a53b07..784d628805d 100644 --- a/src/librustdoc/doctest/runner.rs +++ b/src/librustdoc/doctest/runner.rs @@ -113,6 +113,7 @@ impl DocTestRunner { mod __doctest_mod {{ use std::sync::OnceLock; use std::path::PathBuf; + use std::process::ExitCode; pub static BINARY_PATH: OnceLock<PathBuf> = OnceLock::new(); pub const RUN_OPTION: &str = \"RUSTDOC_DOCTEST_RUN_NB_TEST\"; @@ -123,16 +124,17 @@ mod __doctest_mod {{ }} #[allow(unused)] - pub fn doctest_runner(bin: &std::path::Path, test_nb: usize) -> Result<(), String> {{ + pub fn doctest_runner(bin: &std::path::Path, test_nb: usize) -> ExitCode {{ let out = std::process::Command::new(bin) .env(self::RUN_OPTION, test_nb.to_string()) .args(std::env::args().skip(1).collect::<Vec<_>>()) .output() .expect(\"failed to run command\"); if !out.status.success() {{ - Err(String::from_utf8_lossy(&out.stderr).to_string()) + eprint!(\"{{}}\", String::from_utf8_lossy(&out.stderr)); + ExitCode::FAILURE }} else {{ - Ok(()) + ExitCode::SUCCESS }} }} }} diff --git a/tests/rustdoc-ui/doctest/edition-2024-error-output.rs b/tests/rustdoc-ui/doctest/edition-2024-error-output.rs new file mode 100644 index 00000000000..82a85debcd1 --- /dev/null +++ b/tests/rustdoc-ui/doctest/edition-2024-error-output.rs @@ -0,0 +1,14 @@ +// This is a regression test for <https://github.com/rust-lang/rust/issues/137970>. +// The output must look nice and not like a `Debug` display of a `String`. + +//@ edition: 2024 +//@ compile-flags: --test +//@ normalize-stdout: "tests/rustdoc-ui/doctest" -> "$$DIR" +//@ normalize-stdout: "panicked at .+rs:" -> "panicked at $$TMP:" +//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME" +//@ rustc-env:RUST_BACKTRACE=0 +//@ failure-status: 101 + +//! ```rust +//! assert_eq!(2 + 2, 5); +//! ``` diff --git a/tests/rustdoc-ui/doctest/edition-2024-error-output.stdout b/tests/rustdoc-ui/doctest/edition-2024-error-output.stdout new file mode 100644 index 00000000000..8f056a5f703 --- /dev/null +++ b/tests/rustdoc-ui/doctest/edition-2024-error-output.stdout @@ -0,0 +1,20 @@ + +running 1 test +test $DIR/edition-2024-error-output.rs - (line 12) ... FAILED + +failures: + +---- $DIR/edition-2024-error-output.rs - (line 12) stdout ---- + +thread 'main' panicked at $TMP:6:1: +assertion `left == right` failed + left: 4 + right: 5 +note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace + + +failures: + $DIR/edition-2024-error-output.rs - (line 12) + +test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME + |
