Skip to content

Commit f181ba7

Browse files
tuguzTFirestar99
authored andcommitted
Use new tempdir for each test, allows nextest to pass
1 parent 94f83f1 commit f181ba7

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cargo-gpu/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ semver.workspace = true
2727
dunce.workspace = true
2828

2929
[dev-dependencies]
30+
tempfile.workspace = true
3031
test-log.workspace = true
3132
cargo_metadata = { workspace = true, features = ["builder"] }
3233
cargo-util-schemas = "0.8.2"

crates/cargo-gpu/src/test.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
//! utilities for tests
22
#![cfg(test)]
33

4-
use crate::cache_dir;
5-
use std::io::Write as _;
4+
use std::{cell::RefCell, io::Write as _};
65

76
fn copy_dir_all(
87
src: impl AsRef<std::path::Path>,
@@ -26,10 +25,18 @@ pub fn shader_crate_template_path() -> std::path::PathBuf {
2625
project_base.join("../shader-crate-template")
2726
}
2827

28+
thread_local! {
29+
static TEMPDIR: RefCell<Option<tempfile::TempDir>> = RefCell::new(Some(
30+
tempfile::TempDir::with_prefix("shader_crate").unwrap(),
31+
));
32+
}
33+
2934
pub fn shader_crate_test_path() -> std::path::PathBuf {
30-
let shader_crate_path = crate::cache_dir().unwrap().join("shader_crate");
31-
copy_dir_all(shader_crate_template_path(), shader_crate_path.clone()).unwrap();
32-
shader_crate_path
35+
TEMPDIR.with_borrow(|tempdir| {
36+
let shader_crate_path = tempdir.as_ref().unwrap().path();
37+
copy_dir_all(shader_crate_template_path(), shader_crate_path).unwrap();
38+
shader_crate_path.to_path_buf()
39+
})
3340
}
3441

3542
pub fn overwrite_shader_cargo_toml(shader_crate_path: &std::path::Path) -> std::fs::File {
@@ -45,9 +52,7 @@ pub fn overwrite_shader_cargo_toml(shader_crate_path: &std::path::Path) -> std::
4552
}
4653

4754
pub fn tests_teardown() {
48-
let cache_dir = cache_dir().unwrap();
49-
if !cache_dir.exists() {
50-
return;
51-
}
52-
std::fs::remove_dir_all(cache_dir).unwrap();
55+
TEMPDIR.with_borrow_mut(|tempdir| {
56+
tempdir.take().unwrap().close().unwrap();
57+
});
5358
}

0 commit comments

Comments
 (0)