Add regression test for merged doctests compilation time display
This commit is contained in:
119
tests/run-make/doctests-compilation-time-info/rmake.rs
Normal file
119
tests/run-make/doctests-compilation-time-info/rmake.rs
Normal 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,
|
||||
);
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
//! ```
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user