|
| 1 | +// Check rustdoc's test JUnit (XML) output against snapshots. |
| 2 | + |
| 3 | +//@ ignore-cross-compile (running doctests) |
| 4 | +//@ needs-unwind (test file contains `should_panic` test) |
| 5 | + |
| 6 | +use std::path::Path; |
| 7 | + |
| 8 | +use run_make_support::{cwd, diff, python_command, rustc, rustdoc}; |
| 9 | + |
| 10 | +fn main() { |
| 11 | + let rlib = cwd().join("libdoctest.rlib"); |
| 12 | + rustc().input("doctest.rs").crate_type("rlib").output(&rlib).run(); |
| 13 | + |
| 14 | + run_doctests(&rlib, "2021", "doctest-2021.xml"); |
| 15 | + run_doctests(&rlib, "2024", "doctest-2024.xml"); |
| 16 | +} |
| 17 | + |
| 18 | +#[track_caller] |
| 19 | +fn run_doctests(rlib: &Path, edition: &str, expected_xml: &str) { |
| 20 | + let rustdoc_out = rustdoc() |
| 21 | + .input("doctest.rs") |
| 22 | + .args(&[ |
| 23 | + "--test", |
| 24 | + "--test-args=-Zunstable-options", |
| 25 | + "--test-args=--test-threads=1", |
| 26 | + "--test-args=--format=junit", |
| 27 | + ]) |
| 28 | + .edition(edition) |
| 29 | + .env("RUST_BACKTRACE", "0") |
| 30 | + .extern_("doctest", rlib.display().to_string()) |
| 31 | + .run(); |
| 32 | + let rustdoc_stdout = &rustdoc_out.stdout_utf8(); |
| 33 | + |
| 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 | + } |
| 38 | + |
| 39 | + diff() |
| 40 | + .expected_file(expected_xml) |
| 41 | + .actual_text("output", rustdoc_stdout) |
| 42 | + .normalize(r#"\b(time|total_time|compilation_time)="[0-9.]+""#, r#"$1="$$TIME""#) |
| 43 | + .run(); |
| 44 | +} |
0 commit comments