From 069cf9dfc906452d90d4e2898eac568fb558d25d Mon Sep 17 00:00:00 2001 From: Oleksii Lozovskyi Date: Sat, 29 Nov 2025 09:46:48 +0900 Subject: [PATCH] rustdoc: Write newline differently Fix the panic in write_message() which expects messages to contain no embedded newlines. We still want a trailing newline at the end of the file though, so write it in different manner. Doctest runner no longer panics, but the output is kinda broken when `compile_fail` doctests are present. This is because they are not mergeable. --- library/test/src/formatters/junit.rs | 6 ++- .../run-make/doctests-junit/doctest-2024.xml | 3 ++ tests/run-make/doctests-junit/rmake.rs | 40 +++---------------- 3 files changed, 13 insertions(+), 36 deletions(-) create mode 100644 tests/run-make/doctests-junit/doctest-2024.xml diff --git a/library/test/src/formatters/junit.rs b/library/test/src/formatters/junit.rs index 1566f1cb1dac..74d99e0f1270 100644 --- a/library/test/src/formatters/junit.rs +++ b/library/test/src/formatters/junit.rs @@ -189,8 +189,10 @@ impl OutputFormatter for JunitFormatter { compilation_time: f64, ) -> io::Result<()> { self.write_message(&format!( - "\n", - )) + "", + ))?; + self.out.write_all(b"\n")?; + Ok(()) } } diff --git a/tests/run-make/doctests-junit/doctest-2024.xml b/tests/run-make/doctests-junit/doctest-2024.xml new file mode 100644 index 000000000000..4f94f01c3e32 --- /dev/null +++ b/tests/run-make/doctests-junit/doctest-2024.xml @@ -0,0 +1,3 @@ + + + diff --git a/tests/run-make/doctests-junit/rmake.rs b/tests/run-make/doctests-junit/rmake.rs index 40dc541b5d2c..4cc7ac7c31d7 100644 --- a/tests/run-make/doctests-junit/rmake.rs +++ b/tests/run-make/doctests-junit/rmake.rs @@ -12,7 +12,7 @@ fn main() { rustc().input("doctest.rs").crate_type("rlib").output(&rlib).run(); run_doctests(&rlib, "2021", "doctest-2021.xml"); - run_doctests_fail(&rlib, "2024"); + run_doctests(&rlib, "2024", "doctest-2024.xml"); } #[track_caller] @@ -31,42 +31,14 @@ fn run_doctests(rlib: &Path, edition: &str, expected_xml: &str) { .run(); let rustdoc_stdout = &rustdoc_out.stdout_utf8(); - python_command().arg("validate_junit.py").stdin_buf(rustdoc_stdout).run(); + // FIXME: merged output of compile_fail tests is broken + if edition != "2024" { + python_command().arg("validate_junit.py").stdin_buf(rustdoc_stdout).run(); + } diff() .expected_file(expected_xml) .actual_text("output", rustdoc_stdout) - .normalize(r#"\btime="[0-9.]+""#, r#"time="$$TIME""#) - .run(); -} - -// FIXME: gone in the next patch -#[track_caller] -fn run_doctests_fail(rlib: &Path, edition: &str) { - let rustdoc_out = rustdoc() - .input("doctest.rs") - .args(&[ - "--test", - "--test-args=-Zunstable-options", - "--test-args=--test-threads=1", - "--test-args=--format=junit", - ]) - .edition(edition) - .env("RUST_BACKTRACE", "0") - .extern_("doctest", rlib.display().to_string()) - .run_fail(); - let rustdoc_stderr = &rustdoc_out.stderr_utf8(); - - diff() - .expected_text( - "expected", - r#" -thread 'main' ($TID) panicked at library/test/src/formatters/junit.rs:22:9: -assertion failed: !s.contains('\n') -note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace -"#, - ) - .actual_text("actual", rustdoc_stderr) - .normalize(r#"thread 'main' \([0-9]+\)"#, r#"thread 'main' ($$TID)"#) + .normalize(r#"\b(time|total_time|compilation_time)="[0-9.]+""#, r#"$1="$$TIME""#) .run(); }