Skip to content

Commit 069cf9d

Browse files
committed
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.
1 parent 2cc4348 commit 069cf9d

File tree

3 files changed

+13
-36
lines changed

3 files changed

+13
-36
lines changed

‎library/test/src/formatters/junit.rs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,10 @@ impl<T: Write> OutputFormatter for JunitFormatter<T> {
189189
compilation_time: f64,
190190
) -> io::Result<()> {
191191
self.write_message(&format!(
192-
"<report total_time=\"{total_time}\" compilation_time=\"{compilation_time}\"></report>\n",
193-
))
192+
"<report total_time=\"{total_time}\" compilation_time=\"{compilation_time}\"></report>",
193+
))?;
194+
self.out.write_all(b"\n")?;
195+
Ok(())
194196
}
195197
}
196198

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?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>
2+
<?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>
3+
<report total_time="$TIME" compilation_time="$TIME"></report>

‎tests/run-make/doctests-junit/rmake.rs‎

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn main() {
1212
rustc().input("doctest.rs").crate_type("rlib").output(&rlib).run();
1313

1414
run_doctests(&rlib, "2021", "doctest-2021.xml");
15-
run_doctests_fail(&rlib, "2024");
15+
run_doctests(&rlib, "2024", "doctest-2024.xml");
1616
}
1717

1818
#[track_caller]
@@ -31,42 +31,14 @@ fn run_doctests(rlib: &Path, edition: &str, expected_xml: &str) {
3131
.run();
3232
let rustdoc_stdout = &rustdoc_out.stdout_utf8();
3333

34-
python_command().arg("validate_junit.py").stdin_buf(rustdoc_stdout).run();
34+
// FIXME: merged output of compile_fail tests is broken
35+
if edition != "2024" {
36+
python_command().arg("validate_junit.py").stdin_buf(rustdoc_stdout).run();
37+
}
3538

3639
diff()
3740
.expected_file(expected_xml)
3841
.actual_text("output", rustdoc_stdout)
39-
.normalize(r#"\btime="[0-9.]+""#, r#"time="$$TIME""#)
40-
.run();
41-
}
42-
43-
// FIXME: gone in the next patch
44-
#[track_caller]
45-
fn run_doctests_fail(rlib: &Path, edition: &str) {
46-
let rustdoc_out = rustdoc()
47-
.input("doctest.rs")
48-
.args(&[
49-
"--test",
50-
"--test-args=-Zunstable-options",
51-
"--test-args=--test-threads=1",
52-
"--test-args=--format=junit",
53-
])
54-
.edition(edition)
55-
.env("RUST_BACKTRACE", "0")
56-
.extern_("doctest", rlib.display().to_string())
57-
.run_fail();
58-
let rustdoc_stderr = &rustdoc_out.stderr_utf8();
59-
60-
diff()
61-
.expected_text(
62-
"expected",
63-
r#"
64-
thread 'main' ($TID) panicked at library/test/src/formatters/junit.rs:22:9:
65-
assertion failed: !s.contains('\n')
66-
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
67-
"#,
68-
)
69-
.actual_text("actual", rustdoc_stderr)
70-
.normalize(r#"thread 'main' \([0-9]+\)"#, r#"thread 'main' ($$TID)"#)
42+
.normalize(r#"\b(time|total_time|compilation_time)="[0-9.]+""#, r#"$1="$$TIME""#)
7143
.run();
7244
}

0 commit comments

Comments
 (0)