diff options
| author | Lukas Wirth <lukastw97@gmail.com> | 2024-12-16 10:01:35 +0100 |
|---|---|---|
| committer | Lukas Wirth <lukastw97@gmail.com> | 2024-12-16 10:01:35 +0100 |
| commit | 1cace0aa4135acad746516992bd8e6a89e4fd861 (patch) | |
| tree | 42e799001ffa344e75d32abd38d3e5ba8489a4cd /src/tools/rust-analyzer | |
| parent | 31a462f6e07032d81dbb8521062e6d1608f5da76 (diff) | |
| download | rust-1cace0aa4135acad746516992bd8e6a89e4fd861.tar.gz rust-1cace0aa4135acad746516992bd8e6a89e4fd861.zip | |
internal: Simplify ratoml testdir usage
Diffstat (limited to 'src/tools/rust-analyzer')
| -rw-r--r-- | src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/support.rs | 39 |
1 files changed, 9 insertions, 30 deletions
diff --git a/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/support.rs b/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/support.rs index 5a88a5515c7..1f52f366c54 100644 --- a/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/support.rs +++ b/src/tools/rust-analyzer/crates/rust-analyzer/tests/slow-tests/support.rs @@ -1,7 +1,7 @@ use std::{ cell::{Cell, RefCell}, env, fs, - sync::{Once, OnceLock}, + sync::Once, time::Duration, }; @@ -141,34 +141,15 @@ impl Project<'_> { /// file in the config dir after server is run, something where our naive approach comes short. /// Using a `prelock` allows us to force a lock when we know we need it. pub(crate) fn server_with_lock(self, config_lock: bool) -> Server { - static CONFIG_DIR_LOCK: OnceLock<(Utf8PathBuf, Mutex<()>)> = OnceLock::new(); + static CONFIG_DIR_LOCK: Mutex<()> = Mutex::new(()); let config_dir_guard = if config_lock { Some({ - let (path, mutex) = CONFIG_DIR_LOCK.get_or_init(|| { - let value = TestDir::new().keep().path().to_owned(); - env::set_var("__TEST_RA_USER_CONFIG_DIR", &value); - (value, Mutex::new(())) - }); - #[allow(dyn_drop)] - (mutex.lock(), { - Box::new({ - struct Dropper(Utf8PathBuf); - impl Drop for Dropper { - fn drop(&mut self) { - for entry in fs::read_dir(&self.0).unwrap() { - let path = entry.unwrap().path(); - if path.is_file() { - fs::remove_file(path).unwrap(); - } else if path.is_dir() { - fs::remove_dir_all(path).unwrap(); - } - } - } - } - Dropper(path.clone()) - }) as Box<dyn Drop> - }) + let guard = CONFIG_DIR_LOCK.lock(); + let test_dir = TestDir::new(); + let value = test_dir.path().to_owned(); + env::set_var("__TEST_RA_USER_CONFIG_DIR", &value); + (guard, test_dir) }) } else { None @@ -311,14 +292,12 @@ pub(crate) struct Server { client: Connection, /// XXX: remove the tempdir last dir: TestDir, - #[allow(dyn_drop)] - _config_dir_guard: Option<(MutexGuard<'static, ()>, Box<dyn Drop>)>, + _config_dir_guard: Option<(MutexGuard<'static, ()>, TestDir)>, } impl Server { - #[allow(dyn_drop)] fn new( - config_dir_guard: Option<(MutexGuard<'static, ()>, Box<dyn Drop>)>, + config_dir_guard: Option<(MutexGuard<'static, ()>, TestDir)>, dir: TestDir, config: Config, ) -> Server { |
