diff --git a/crates/cargo-test-macro/src/lib.rs b/crates/cargo-test-macro/src/lib.rs index 5f0eecfeb6c..8acf4f114fb 100644 --- a/crates/cargo-test-macro/src/lib.rs +++ b/crates/cargo-test-macro/src/lib.rs @@ -219,7 +219,7 @@ pub fn cargo_test(attr: TokenStream, item: TokenStream) -> TokenStream { let mut new_body = to_token_stream( r#"let _test_guard = { - let tmp_dir = option_env!("CARGO_TARGET_TMPDIR"); + let tmp_dir = env!("CARGO_TARGET_TMPDIR"); cargo_test_support::paths::init_root(tmp_dir) };"#, ); diff --git a/crates/cargo-test-support/src/paths.rs b/crates/cargo-test-support/src/paths.rs index 9c08afa9020..c6d91c1bd52 100644 --- a/crates/cargo-test-support/src/paths.rs +++ b/crates/cargo-test-support/src/paths.rs @@ -5,7 +5,6 @@ use itertools::Itertools; use walkdir::WalkDir; use std::cell::RefCell; -use std::env; use std::fs; use std::io::{self, ErrorKind}; use std::path::{Path, PathBuf}; @@ -21,28 +20,13 @@ static CARGO_INTEGRATION_TEST_DIR: &str = "cit"; static GLOBAL_ROOT: OnceLock>> = OnceLock::new(); -/// This is used when running cargo is pre-CARGO_TARGET_TMPDIR -/// TODO: Remove when `CARGO_TARGET_TMPDIR` grows old enough. -fn global_root_legacy() -> PathBuf { - let mut path = t!(env::current_exe()); - path.pop(); // chop off exe name - path.pop(); // chop off "deps" - path.push("tmp"); - path.mkdir_p(); - path -} - -fn set_global_root(tmp_dir: Option<&'static str>) { +fn set_global_root(tmp_dir: &'static str) { let mut lock = GLOBAL_ROOT .get_or_init(|| Default::default()) .lock() .unwrap(); if lock.is_none() { - let mut root = match tmp_dir { - Some(tmp_dir) => PathBuf::from(tmp_dir), - None => global_root_legacy(), - }; - + let mut root = PathBuf::from(tmp_dir); root.push(CARGO_INTEGRATION_TEST_DIR); *lock = Some(root); } @@ -80,7 +64,7 @@ pub struct TestIdGuard { } /// For test harnesses like [`crate::cargo_test`] -pub fn init_root(tmp_dir: Option<&'static str>) -> TestIdGuard { +pub fn init_root(tmp_dir: &'static str) -> TestIdGuard { static NEXT_ID: AtomicUsize = AtomicUsize::new(0); let id = NEXT_ID.fetch_add(1, Ordering::SeqCst);