Skip to content

Commit 5a77d88

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

File tree

1 file changed

+119
-0
lines changed
  • tests/run-make/doctests-compilation-time-info

1 file changed

+119
-0
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 check_present_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+
check_present_of_compilation_time_report(
31+
"\
32+
//! ```
33+
//! let x = 12;
34+
//! ```",
35+
true,
36+
true,
37+
);
38+
// Checking with only fainling merged doctests.
39+
check_present_of_compilation_time_report(
40+
"\
41+
//! ```
42+
//! panic!();
43+
//! ```",
44+
false,
45+
true,
46+
);
47+
// Checking with mix of successful doctests.
48+
check_present_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+
check_present_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+
check_present_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+
check_present_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+
check_present_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+
check_present_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+
}

0 commit comments

Comments
 (0)