aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock24
-rw-r--r--crates/rust-analyzer/Cargo.toml1
-rw-r--r--crates/rust-analyzer/tests/heavy_tests/main.rs9
-rw-r--r--crates/rust-analyzer/tests/heavy_tests/support.rs13
-rw-r--r--crates/rust-analyzer/tests/heavy_tests/testdir.rs62
5 files changed, 75 insertions, 34 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 007b0d6a5..0a35eb793 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1327,15 +1327,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1327checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8" 1327checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8"
1328 1328
1329[[package]] 1329[[package]]
1330name = "remove_dir_all"
1331version = "0.5.3"
1332source = "registry+https://github.com/rust-lang/crates.io-index"
1333checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
1334dependencies = [
1335 "winapi 0.3.9",
1336]
1337
1338[[package]]
1339name = "rowan" 1330name = "rowan"
1340version = "0.10.0" 1331version = "0.10.0"
1341source = "registry+https://github.com/rust-lang/crates.io-index" 1332source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1386,7 +1377,6 @@ dependencies = [
1386 "serde", 1377 "serde",
1387 "serde_json", 1378 "serde_json",
1388 "stdx", 1379 "stdx",
1389 "tempfile",
1390 "test_utils", 1380 "test_utils",
1391 "threadpool", 1381 "threadpool",
1392 "vfs", 1382 "vfs",
@@ -1607,20 +1597,6 @@ dependencies = [
1607] 1597]
1608 1598
1609[[package]] 1599[[package]]
1610name = "tempfile"
1611version = "3.1.0"
1612source = "registry+https://github.com/rust-lang/crates.io-index"
1613checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9"
1614dependencies = [
1615 "cfg-if",
1616 "libc",
1617 "rand",
1618 "redox_syscall",
1619 "remove_dir_all",
1620 "winapi 0.3.9",
1621]
1622
1623[[package]]
1624name = "termcolor" 1600name = "termcolor"
1625version = "1.1.0" 1601version = "1.1.0"
1626source = "registry+https://github.com/rust-lang/crates.io-index" 1602source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml
index 758aa1c5d..3f9c820c5 100644
--- a/crates/rust-analyzer/Cargo.toml
+++ b/crates/rust-analyzer/Cargo.toml
@@ -58,7 +58,6 @@ ra_proc_macro_srv = { path = "../ra_proc_macro_srv" }
58winapi = "0.3.8" 58winapi = "0.3.8"
59 59
60[dev-dependencies] 60[dev-dependencies]
61tempfile = "3.1.0"
62expect = { path = "../expect" } 61expect = { path = "../expect" }
63test_utils = { path = "../test_utils" } 62test_utils = { path = "../test_utils" }
64mbe = { path = "../ra_mbe", package = "ra_mbe" } 63mbe = { path = "../ra_mbe", package = "ra_mbe" }
diff --git a/crates/rust-analyzer/tests/heavy_tests/main.rs b/crates/rust-analyzer/tests/heavy_tests/main.rs
index 93448834f..28e896648 100644
--- a/crates/rust-analyzer/tests/heavy_tests/main.rs
+++ b/crates/rust-analyzer/tests/heavy_tests/main.rs
@@ -1,3 +1,4 @@
1mod testdir;
1mod support; 2mod support;
2 3
3use std::{collections::HashMap, path::PathBuf, time::Instant}; 4use std::{collections::HashMap, path::PathBuf, time::Instant};
@@ -12,10 +13,12 @@ use lsp_types::{
12}; 13};
13use rust_analyzer::lsp_ext::{OnEnter, Runnables, RunnablesParams}; 14use rust_analyzer::lsp_ext::{OnEnter, Runnables, RunnablesParams};
14use serde_json::json; 15use serde_json::json;
15use tempfile::TempDir;
16use test_utils::skip_slow_tests; 16use test_utils::skip_slow_tests;
17 17
18use crate::support::{project, Project}; 18use crate::{
19 support::{project, Project},
20 testdir::TestDir,
21};
19 22
20const PROFILE: &str = ""; 23const PROFILE: &str = "";
21// const PROFILE: &'static str = "*@3>100"; 24// const PROFILE: &'static str = "*@3>100";
@@ -308,7 +311,7 @@ fn test_missing_module_code_action_in_json_project() {
308 return; 311 return;
309 } 312 }
310 313
311 let tmp_dir = TempDir::new().unwrap(); 314 let tmp_dir = TestDir::new();
312 315
313 let path = tmp_dir.path(); 316 let path = tmp_dir.path();
314 317
diff --git a/crates/rust-analyzer/tests/heavy_tests/support.rs b/crates/rust-analyzer/tests/heavy_tests/support.rs
index e51796d36..e152264d3 100644
--- a/crates/rust-analyzer/tests/heavy_tests/support.rs
+++ b/crates/rust-analyzer/tests/heavy_tests/support.rs
@@ -19,14 +19,15 @@ use rust_analyzer::{
19}; 19};
20use serde::Serialize; 20use serde::Serialize;
21use serde_json::{to_string_pretty, Value}; 21use serde_json::{to_string_pretty, Value};
22use tempfile::TempDir;
23use test_utils::{find_mismatch, Fixture}; 22use test_utils::{find_mismatch, Fixture};
24use vfs::AbsPathBuf; 23use vfs::AbsPathBuf;
25 24
25use crate::testdir::TestDir;
26
26pub struct Project<'a> { 27pub struct Project<'a> {
27 fixture: &'a str, 28 fixture: &'a str,
28 with_sysroot: bool, 29 with_sysroot: bool,
29 tmp_dir: Option<TempDir>, 30 tmp_dir: Option<TestDir>,
30 roots: Vec<PathBuf>, 31 roots: Vec<PathBuf>,
31 config: Option<Box<dyn Fn(&mut Config)>>, 32 config: Option<Box<dyn Fn(&mut Config)>>,
32} 33}
@@ -36,7 +37,7 @@ impl<'a> Project<'a> {
36 Project { fixture, tmp_dir: None, roots: vec![], with_sysroot: false, config: None } 37 Project { fixture, tmp_dir: None, roots: vec![], with_sysroot: false, config: None }
37 } 38 }
38 39
39 pub fn tmp_dir(mut self, tmp_dir: TempDir) -> Project<'a> { 40 pub fn tmp_dir(mut self, tmp_dir: TestDir) -> Project<'a> {
40 self.tmp_dir = Some(tmp_dir); 41 self.tmp_dir = Some(tmp_dir);
41 self 42 self
42 } 43 }
@@ -57,7 +58,7 @@ impl<'a> Project<'a> {
57 } 58 }
58 59
59 pub fn server(self) -> Server { 60 pub fn server(self) -> Server {
60 let tmp_dir = self.tmp_dir.unwrap_or_else(|| TempDir::new().unwrap()); 61 let tmp_dir = self.tmp_dir.unwrap_or_else(|| TestDir::new());
61 static INIT: Once = Once::new(); 62 static INIT: Once = Once::new();
62 INIT.call_once(|| { 63 INIT.call_once(|| {
63 env_logger::builder().is_test(true).try_init().unwrap(); 64 env_logger::builder().is_test(true).try_init().unwrap();
@@ -112,11 +113,11 @@ pub struct Server {
112 _thread: jod_thread::JoinHandle<()>, 113 _thread: jod_thread::JoinHandle<()>,
113 client: Connection, 114 client: Connection,
114 /// XXX: remove the tempdir last 115 /// XXX: remove the tempdir last
115 dir: TempDir, 116 dir: TestDir,
116} 117}
117 118
118impl Server { 119impl Server {
119 fn new(dir: TempDir, config: Config) -> Server { 120 fn new(dir: TestDir, config: Config) -> Server {
120 let (connection, client) = Connection::memory(); 121 let (connection, client) = Connection::memory();
121 122
122 let _thread = jod_thread::Builder::new() 123 let _thread = jod_thread::Builder::new()
diff --git a/crates/rust-analyzer/tests/heavy_tests/testdir.rs b/crates/rust-analyzer/tests/heavy_tests/testdir.rs
new file mode 100644
index 000000000..7487e7429
--- /dev/null
+++ b/crates/rust-analyzer/tests/heavy_tests/testdir.rs
@@ -0,0 +1,62 @@
1use std::{
2 fs, io,
3 path::{Path, PathBuf},
4 sync::atomic::{AtomicUsize, Ordering},
5};
6
7pub struct TestDir {
8 path: PathBuf,
9 keep: bool,
10}
11
12impl TestDir {
13 pub fn new() -> TestDir {
14 let base = std::env::temp_dir().join("testdir");
15 let pid = std::process::id();
16
17 static CNT: AtomicUsize = AtomicUsize::new(0);
18 for _ in 0..100 {
19 let cnt = CNT.fetch_add(1, Ordering::Relaxed);
20 let path = base.join(format!("{}_{}", pid, cnt));
21 if path.is_dir() {
22 continue;
23 }
24 fs::create_dir_all(&path).unwrap();
25 return TestDir { path, keep: false };
26 }
27 panic!("Failed to create a temporary directory")
28 }
29 #[allow(unused)]
30 pub fn keep(mut self) -> TestDir {
31 self.keep = true;
32 self
33 }
34 pub fn path(&self) -> &Path {
35 &self.path
36 }
37}
38
39impl Drop for TestDir {
40 fn drop(&mut self) {
41 if self.keep {
42 return;
43 }
44 remove_dir_all(&self.path).unwrap()
45 }
46}
47
48#[cfg(not(windows))]
49fn remove_dir_all(path: &Path) -> io::Result<()> {
50 fs::remove_dir_all(path)
51}
52
53#[cfg(windows)]
54fn remove_dir_all(path: &Path) -> io::Result<()> {
55 for _ in 0..99 {
56 if fs::remove_dir_all(path).is_ok() {
57 return Ok(());
58 }
59 std::thread::sleep(std::time::Duration::from_millis(10))
60 }
61 fs::remove_dir_all(path)
62}