Skip to content

Fix 2024 edition doctest panic output #139328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 5, 2025
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
8 changes: 5 additions & 3 deletions src/librustdoc/doctest/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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\";
Expand All @@ -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
}}
}}
}}
Expand Down
14 changes: 14 additions & 0 deletions tests/rustdoc-ui/doctest/edition-2024-error-output.rs
Original file line number Diff line number Diff line change
@@ -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);
//! ```
20 changes: 20 additions & 0 deletions tests/rustdoc-ui/doctest/edition-2024-error-output.stdout
Original file line number Diff line number Diff line change
@@ -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

Loading