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.
This commit is contained in:
Oleksii Lozovskyi 2025-11-29 09:46:48 +09:00
parent 2cc434863c
commit 069cf9dfc9
3 changed files with 13 additions and 36 deletions

View file

@ -189,8 +189,10 @@ impl<T: Write> OutputFormatter for JunitFormatter<T> {
compilation_time: f64,
) -> io::Result<()> {
self.write_message(&format!(
"<report total_time=\"{total_time}\" compilation_time=\"{compilation_time}\"></report>\n",
))
"<report total_time=\"{total_time}\" compilation_time=\"{compilation_time}\"></report>",
))?;
self.out.write_all(b"\n")?;
Ok(())
}
}

View file

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?><testsuites><testsuite name="test" package="test" id="0" errors="0" failures="0" tests="2" skipped="0" ><testcase classname="doctest.rs" name="add (line 1)" time="$TIME"/><testcase classname="doctest.rs" name="add (line 5)" time="$TIME"/><system-out/><system-err/></testsuite></testsuites>
<?xml version="1.0" encoding="UTF-8"?><testsuites><testsuite name="test" package="test" id="0" errors="0" failures="0" tests="1" skipped="0" ><testcase classname="doctest.rs" name="add (line 9)" time="$TIME"/><system-out/><system-err/></testsuite></testsuites>
<report total_time="$TIME" compilation_time="$TIME"></report>

View file

@ -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();
}