|
| 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_fail(&rlib, "2024"); |
| 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 | + python_command().arg("validate_junit.py").stdin_buf(rustdoc_stdout).run(); |
| 35 | + |
| 36 | + diff() |
| 37 | + .expected_file(expected_xml) |
| 38 | + .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)"#) |
| 71 | + .run(); |
| 72 | +} |
0 commit comments