Skip to content

Commit 442ae63

Browse files
Add regression test for #139899
1 parent 173cdaf commit 442ae63

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#![doc(test(attr(deny(warnings))))]
2+
3+
//! ```
4+
//! let a = 12;
5+
//! ```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// This test ensures that no temporary folder is "left behind" when doctests fail for any reason.
2+
3+
//@ only-linux
4+
5+
use std::path::Path;
6+
7+
use run_make_support::{path, rfs, rustdoc};
8+
9+
fn run_doctest_and_check_tmpdir(tmp_dir: &Path, doctest: &str, edition: &str) {
10+
let output =
11+
rustdoc().input(doctest).env("TMPDIR", tmp_dir).arg("--test").edition(edition).run_fail();
12+
13+
output.assert_exit_code(101).assert_stdout_contains(
14+
"test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out",
15+
);
16+
17+
rfs::read_dir_entries(tmp_dir, |entry| {
18+
panic!("Found an item inside the temporary folder: {entry:?}");
19+
});
20+
}
21+
22+
fn run_doctest_and_check_tmpdir_for_edition(tmp_dir: &Path, edition: &str) {
23+
run_doctest_and_check_tmpdir(tmp_dir, "compile-error.rs", edition);
24+
run_doctest_and_check_tmpdir(tmp_dir, "run-error.rs", edition);
25+
}
26+
27+
fn main() {
28+
let tmp_dir = path("tmp");
29+
rfs::create_dir(&tmp_dir);
30+
31+
run_doctest_and_check_tmpdir_for_edition(&tmp_dir, "2018");
32+
// We use the 2024 edition to check that it's also working for merged doctests.
33+
run_doctest_and_check_tmpdir_for_edition(&tmp_dir, "2024");
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//! ```
2+
//! panic!();
3+
//! ```

0 commit comments

Comments
 (0)