Skip to content

Commit 2cb8b0b

Browse files
Move the creation of IndividualTestOptions into the test runner closure to ensure the temporary folder is removed right after the test is done running
1 parent b542750 commit 2cb8b0b

7 files changed

Lines changed: 67 additions & 7 deletions

File tree

‎src/librustdoc/doctest.rs‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ pub(crate) struct RunnableDocTest<'a> {
575575
/// In a standalone test this is just the regular test code.
576576
full_test_code: String,
577577
full_test_line_offset: usize,
578-
test_opts: &'a IndividualTestOptions,
578+
test_opts: IndividualTestOptions,
579579
global_opts: &'a GlobalTestOptions,
580580
langstr: LangString,
581581
line: usize,
@@ -1143,8 +1143,6 @@ fn generate_test_desc_and_fn(
11431143
unused_externs: Arc<Mutex<Vec<UnusedExterns>>>,
11441144
) -> test::TestDescAndFn {
11451145
let target_str = rustdoc_options.target.to_string();
1146-
let rustdoc_test_options =
1147-
IndividualTestOptions::new(&rustdoc_options, &test.test_id, scraped_test.local_path());
11481146

11491147
debug!("creating test {}: {}", scraped_test.name, scraped_test.text);
11501148
test::TestDescAndFn {
@@ -1168,8 +1166,13 @@ fn generate_test_desc_and_fn(
11681166
test_type: test::TestType::DocTest,
11691167
},
11701168
testfn: test::DynTestFn(Arc::new(move || {
1169+
let rustdoc_test_options = IndividualTestOptions::new(
1170+
&rustdoc_options,
1171+
&test.test_id,
1172+
scraped_test.local_path(),
1173+
);
11711174
doctest_run_fn(
1172-
&rustdoc_test_options,
1175+
rustdoc_test_options,
11731176
&opts,
11741177
&test,
11751178
&scraped_test,
@@ -1181,7 +1184,7 @@ fn generate_test_desc_and_fn(
11811184
}
11821185

11831186
fn doctest_run_fn(
1184-
test_opts: &IndividualTestOptions,
1187+
test_opts: IndividualTestOptions,
11851188
global_opts: &GlobalTestOptions,
11861189
doctest: &DocTestBuilder,
11871190
scraped_test: &ScrapedDocTest,

‎src/librustdoc/doctest/runner.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ test::test_main(test_args, tests)
198198
let runnable_test = RunnableDocTest {
199199
full_test_code: format!("{code_prefix}{code}", code = self.output),
200200
full_test_line_offset: 0,
201-
test_opts: &test_options,
201+
test_opts: test_options,
202202
global_opts: opts,
203203
langstr: LangString::default(),
204204
line: 0,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// ```
2+
/// assert!(true);
3+
/// ```
4+
pub fn a() {}
5+
6+
/// ```
7+
/// let count = std::fs::read_dir(std::env::temp_dir())
8+
/// .unwrap()
9+
/// .filter(|entry| {
10+
/// entry.as_ref().unwrap().file_name().to_str().unwrap().starts_with("rustdoctest")
11+
/// })
12+
/// .count();
13+
/// // It's 2 and not one because rustdoc creates a temp dir where it puts the `rustdoc-cfgs`
14+
/// // file which contains the list of flags to be passed down to the doctests. It lives
15+
/// // until all doctests have been run.
16+
/// assert_eq!(count, 2);
17+
/// ```
18+
pub fn b() {}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// This test ensures that a temporary doctest directory is removed as soon as the doctest
2+
// was run to prevent "No space left on device". To ensure it works, we use a file with two
3+
// doctests, run without the "merged doctests" feature (hence the "2021" edition) with
4+
// one thread to prevent potential concurrent cleanups.
5+
// Regression test for <https://github.com/rust-lang/rust/issues/164145>.
6+
7+
//@ ignore-cross-compile
8+
//@ only-linux
9+
10+
use run_make_support::{is_windows, path, rfs, rustdoc};
11+
12+
fn main() {
13+
let tmp = path("tmp");
14+
rfs::create_dir(&tmp);
15+
16+
let mut cmd = rustdoc()
17+
.env("TMPDIR", &tmp)
18+
.input("lib.rs")
19+
.edition("2021")
20+
.arg("--test")
21+
.arg("--test-args=--test-threads=1")
22+
.run();
23+
}

‎tests/rustdoc-ui/issues/issue-98690.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//@ compile-flags: --test --persist-doctests /../../ -Z unstable-options
22
//@ failure-status: 101
33
//@ only-linux
4+
//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME"
5+
//@ normalize-stdout: ".rs:\d+:\d+" -> ".rs:$$LINE:$$COL"
46

57
#![crate_name = "foo"]
68

‎tests/rustdoc-ui/issues/issue-98690.stderr‎

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
running 1 test
3+
test $DIR/issue-98690.rs - (line 9) ... FAILED
4+
5+
failures:
6+
7+
---- $DIR/issue-98690.rs - (line 9) stdout ----
8+
Couldn't create directory for doctest executables: Permission denied (os error 13)
9+
10+
11+
failures:
12+
$DIR/issue-98690.rs - (line 9)
13+
14+
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
15+

0 commit comments

Comments
 (0)