Skip to content

Commit b7e444d

Browse files
Add regression test for merged doctests compilation time display
1 parent 9877b26 commit b7e444d

File tree

8 files changed

+136
-8
lines changed

8 files changed

+136
-8
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
//@ ignore-cross-compile (needs to run doctests)
2+
3+
use run_make_support::rfs::write;
4+
use run_make_support::{cwd, rustdoc};
5+
6+
fn assert_presence_of_compilation_time_report(
7+
content: &str,
8+
success: bool,
9+
should_contain_compile_time: bool,
10+
) {
11+
let mut cmd = rustdoc();
12+
let file = cwd().join("foo.rs");
13+
14+
write(&file, content);
15+
cmd.input(&file).arg("--test").edition("2024").env("RUST_BACKTRACE", "0");
16+
let output = if success { cmd.run() } else { cmd.run_fail() };
17+
18+
assert_eq!(
19+
output
20+
.stdout_utf8()
21+
.split("all doctests ran in ")
22+
.last()
23+
.is_some_and(|s| s.contains("; merged doctests compilation took")),
24+
should_contain_compile_time,
25+
);
26+
}
27+
28+
fn main() {
29+
// Checking with only successful merged doctests.
30+
assert_presence_of_compilation_time_report(
31+
"\
32+
//! ```
33+
//! let x = 12;
34+
//! ```",
35+
true,
36+
true,
37+
);
38+
// Checking with only failing merged doctests.
39+
assert_presence_of_compilation_time_report(
40+
"\
41+
//! ```
42+
//! panic!();
43+
//! ```",
44+
false,
45+
true,
46+
);
47+
// Checking with mix of successful doctests.
48+
assert_presence_of_compilation_time_report(
49+
"\
50+
//! ```
51+
//! let x = 12;
52+
//! ```
53+
//!
54+
//! ```compile_fail
55+
//! let x
56+
//! ```",
57+
true,
58+
true,
59+
);
60+
// Checking with mix of failing doctests.
61+
assert_presence_of_compilation_time_report(
62+
"\
63+
//! ```
64+
//! panic!();
65+
//! ```
66+
//!
67+
//! ```compile_fail
68+
//! let x
69+
//! ```",
70+
false,
71+
true,
72+
);
73+
// Checking with mix of failing doctests (v2).
74+
assert_presence_of_compilation_time_report(
75+
"\
76+
//! ```
77+
//! let x = 12;
78+
//! ```
79+
//!
80+
//! ```compile_fail
81+
//! let x = 12;
82+
//! ```",
83+
false,
84+
true,
85+
);
86+
// Checking with mix of failing doctests (v3).
87+
assert_presence_of_compilation_time_report(
88+
"\
89+
//! ```
90+
//! panic!();
91+
//! ```
92+
//!
93+
//! ```compile_fail
94+
//! let x = 12;
95+
//! ```",
96+
false,
97+
true,
98+
);
99+
// Checking with successful non-merged doctests.
100+
assert_presence_of_compilation_time_report(
101+
"\
102+
//! ```compile_fail
103+
//! let x
104+
//! ```",
105+
true,
106+
// If there is no merged doctests, then we should not display compilation time.
107+
false,
108+
);
109+
// Checking with failing non-merged doctests.
110+
assert_presence_of_compilation_time_report(
111+
"\
112+
//! ```compile_fail
113+
//! let x = 12;
114+
//! ```",
115+
false,
116+
// If there is no merged doctests, then we should not display compilation time.
117+
false,
118+
);
119+
}

tests/run-make/doctests-merge/doctest-2024.stdout

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ test doctest.rs - init (line 8) ... ok
55

66
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
77

8+
all doctests ran in $TIME; merged doctests compilation took $TIME

tests/run-make/doctests-merge/rmake.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ fn test_and_compare(input_file: &str, stdout_file: &str, edition: &str, dep: &Pa
2020
.expected_file(stdout_file)
2121
.actual_text("output", output.stdout_utf8())
2222
.normalize(r#"finished in \d+\.\d+s"#, "finished in $$TIME")
23+
.normalize(r#"ran in \d+\.\d+s"#, "ran in $$TIME")
24+
.normalize(r#"compilation took \d+\.\d+s"#, "compilation took $$TIME")
2325
.run();
2426
}
2527

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

22
running 3 tests
3-
test $DIR/doctest-output.rs - (line 12) ... ok
4-
test $DIR/doctest-output.rs - ExpandedStruct (line 28) ... ok
5-
test $DIR/doctest-output.rs - foo::bar (line 22) ... ok
3+
test $DIR/doctest-output.rs - (line 14) ... ok
4+
test $DIR/doctest-output.rs - ExpandedStruct (line 30) ... ok
5+
test $DIR/doctest-output.rs - foo::bar (line 24) ... ok
66

77
test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
88

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11

22
running 3 tests
3-
test $DIR/doctest-output.rs - (line 12) ... ok
4-
test $DIR/doctest-output.rs - ExpandedStruct (line 28) ... ok
5-
test $DIR/doctest-output.rs - foo::bar (line 22) ... ok
3+
test $DIR/doctest-output.rs - (line 14) ... ok
4+
test $DIR/doctest-output.rs - ExpandedStruct (line 30) ... ok
5+
test $DIR/doctest-output.rs - foo::bar (line 24) ... ok
66

77
test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
88

9+
all doctests ran in $TIME; merged doctests compilation took $TIME

tests/rustdoc-ui/doctest/doctest-output.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
//@[edition2024]compile-flags:--test --test-args=--test-threads=1
88
//@ normalize-stdout: "tests/rustdoc-ui/doctest" -> "$$DIR"
99
//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME"
10+
//@ normalize-stdout: "ran in \d+\.\d+s" -> "ran in $$TIME"
11+
//@ normalize-stdout: "compilation took \d+\.\d+s" -> "compilation took $$TIME"
1012
//@ check-pass
1113

1214
//! ```

tests/rustdoc-ui/doctest/merged-ignore-no_run.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
//@ compile-flags:--test --test-args=--test-threads=1
33
//@ normalize-stdout: "tests/rustdoc-ui/doctest" -> "$$DIR"
44
//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME"
5+
//@ normalize-stdout: "ran in \d+\.\d+s" -> "ran in $$TIME"
6+
//@ normalize-stdout: "compilation took \d+\.\d+s" -> "compilation took $$TIME"
57
//@ check-pass
68

79
/// ```ignore (test)
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11

22
running 2 tests
3-
test $DIR/merged-ignore-no_run.rs - ignored (line 7) ... ignored
4-
test $DIR/merged-ignore-no_run.rs - no_run (line 12) - compile ... ok
3+
test $DIR/merged-ignore-no_run.rs - ignored (line 9) ... ignored
4+
test $DIR/merged-ignore-no_run.rs - no_run (line 14) - compile ... ok
55

66
test result: ok. 1 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in $TIME
77

8+
all doctests ran in $TIME; merged doctests compilation took $TIME

0 commit comments

Comments
 (0)