Add regression test for merged doctests compilation time display

This commit is contained in:
Guillaume Gomez
2025-09-25 16:43:01 +02:00
parent 9877b26fd1
commit b7e444de16
8 changed files with 136 additions and 8 deletions

View File

@@ -0,0 +1,119 @@
//@ ignore-cross-compile (needs to run doctests)
use run_make_support::rfs::write;
use run_make_support::{cwd, rustdoc};
fn assert_presence_of_compilation_time_report(
content: &str,
success: bool,
should_contain_compile_time: bool,
) {
let mut cmd = rustdoc();
let file = cwd().join("foo.rs");
write(&file, content);
cmd.input(&file).arg("--test").edition("2024").env("RUST_BACKTRACE", "0");
let output = if success { cmd.run() } else { cmd.run_fail() };
assert_eq!(
output
.stdout_utf8()
.split("all doctests ran in ")
.last()
.is_some_and(|s| s.contains("; merged doctests compilation took")),
should_contain_compile_time,
);
}
fn main() {
// Checking with only successful merged doctests.
assert_presence_of_compilation_time_report(
"\
//! ```
//! let x = 12;
//! ```",
true,
true,
);
// Checking with only failing merged doctests.
assert_presence_of_compilation_time_report(
"\
//! ```
//! panic!();
//! ```",
false,
true,
);
// Checking with mix of successful doctests.
assert_presence_of_compilation_time_report(
"\
//! ```
//! let x = 12;
//! ```
//!
//! ```compile_fail
//! let x
//! ```",
true,
true,
);
// Checking with mix of failing doctests.
assert_presence_of_compilation_time_report(
"\
//! ```
//! panic!();
//! ```
//!
//! ```compile_fail
//! let x
//! ```",
false,
true,
);
// Checking with mix of failing doctests (v2).
assert_presence_of_compilation_time_report(
"\
//! ```
//! let x = 12;
//! ```
//!
//! ```compile_fail
//! let x = 12;
//! ```",
false,
true,
);
// Checking with mix of failing doctests (v3).
assert_presence_of_compilation_time_report(
"\
//! ```
//! panic!();
//! ```
//!
//! ```compile_fail
//! let x = 12;
//! ```",
false,
true,
);
// Checking with successful non-merged doctests.
assert_presence_of_compilation_time_report(
"\
//! ```compile_fail
//! let x
//! ```",
true,
// If there is no merged doctests, then we should not display compilation time.
false,
);
// Checking with failing non-merged doctests.
assert_presence_of_compilation_time_report(
"\
//! ```compile_fail
//! let x = 12;
//! ```",
false,
// If there is no merged doctests, then we should not display compilation time.
false,
);
}

View File

@@ -5,3 +5,4 @@ test doctest.rs - init (line 8) ... ok
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
all doctests ran in $TIME; merged doctests compilation took $TIME

View File

@@ -20,6 +20,8 @@ fn test_and_compare(input_file: &str, stdout_file: &str, edition: &str, dep: &Pa
.expected_file(stdout_file)
.actual_text("output", output.stdout_utf8())
.normalize(r#"finished in \d+\.\d+s"#, "finished in $$TIME")
.normalize(r#"ran in \d+\.\d+s"#, "ran in $$TIME")
.normalize(r#"compilation took \d+\.\d+s"#, "compilation took $$TIME")
.run();
}

View File

@@ -1,8 +1,8 @@
running 3 tests
test $DIR/doctest-output.rs - (line 12) ... ok
test $DIR/doctest-output.rs - ExpandedStruct (line 28) ... ok
test $DIR/doctest-output.rs - foo::bar (line 22) ... ok
test $DIR/doctest-output.rs - (line 14) ... ok
test $DIR/doctest-output.rs - ExpandedStruct (line 30) ... ok
test $DIR/doctest-output.rs - foo::bar (line 24) ... ok
test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME

View File

@@ -1,8 +1,9 @@
running 3 tests
test $DIR/doctest-output.rs - (line 12) ... ok
test $DIR/doctest-output.rs - ExpandedStruct (line 28) ... ok
test $DIR/doctest-output.rs - foo::bar (line 22) ... ok
test $DIR/doctest-output.rs - (line 14) ... ok
test $DIR/doctest-output.rs - ExpandedStruct (line 30) ... ok
test $DIR/doctest-output.rs - foo::bar (line 24) ... ok
test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
all doctests ran in $TIME; merged doctests compilation took $TIME

View File

@@ -7,6 +7,8 @@
//@[edition2024]compile-flags:--test --test-args=--test-threads=1
//@ normalize-stdout: "tests/rustdoc-ui/doctest" -> "$$DIR"
//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME"
//@ normalize-stdout: "ran in \d+\.\d+s" -> "ran in $$TIME"
//@ normalize-stdout: "compilation took \d+\.\d+s" -> "compilation took $$TIME"
//@ check-pass
//! ```

View File

@@ -2,6 +2,8 @@
//@ compile-flags:--test --test-args=--test-threads=1
//@ normalize-stdout: "tests/rustdoc-ui/doctest" -> "$$DIR"
//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME"
//@ normalize-stdout: "ran in \d+\.\d+s" -> "ran in $$TIME"
//@ normalize-stdout: "compilation took \d+\.\d+s" -> "compilation took $$TIME"
//@ check-pass
/// ```ignore (test)

View File

@@ -1,7 +1,8 @@
running 2 tests
test $DIR/merged-ignore-no_run.rs - ignored (line 7) ... ignored
test $DIR/merged-ignore-no_run.rs - no_run (line 12) - compile ... ok
test $DIR/merged-ignore-no_run.rs - ignored (line 9) ... ignored
test $DIR/merged-ignore-no_run.rs - no_run (line 14) - compile ... ok
test result: ok. 1 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in $TIME
all doctests ran in $TIME; merged doctests compilation took $TIME