diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/rust-analyzer/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/rust-analyzer/tests/heavy_tests/main.rs | 9 | ||||
-rw-r--r-- | crates/rust-analyzer/tests/heavy_tests/support.rs | 13 | ||||
-rw-r--r-- | crates/rust-analyzer/tests/heavy_tests/testdir.rs | 62 |
4 files changed, 75 insertions, 10 deletions
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" } | |||
58 | winapi = "0.3.8" | 58 | winapi = "0.3.8" |
59 | 59 | ||
60 | [dev-dependencies] | 60 | [dev-dependencies] |
61 | tempfile = "3.1.0" | ||
62 | expect = { path = "../expect" } | 61 | expect = { path = "../expect" } |
63 | test_utils = { path = "../test_utils" } | 62 | test_utils = { path = "../test_utils" } |
64 | mbe = { path = "../ra_mbe", package = "ra_mbe" } | 63 | mbe = { 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 @@ | |||
1 | mod testdir; | ||
1 | mod support; | 2 | mod support; |
2 | 3 | ||
3 | use std::{collections::HashMap, path::PathBuf, time::Instant}; | 4 | use std::{collections::HashMap, path::PathBuf, time::Instant}; |
@@ -12,10 +13,12 @@ use lsp_types::{ | |||
12 | }; | 13 | }; |
13 | use rust_analyzer::lsp_ext::{OnEnter, Runnables, RunnablesParams}; | 14 | use rust_analyzer::lsp_ext::{OnEnter, Runnables, RunnablesParams}; |
14 | use serde_json::json; | 15 | use serde_json::json; |
15 | use tempfile::TempDir; | ||
16 | use test_utils::skip_slow_tests; | 16 | use test_utils::skip_slow_tests; |
17 | 17 | ||
18 | use crate::support::{project, Project}; | 18 | use crate::{ |
19 | support::{project, Project}, | ||
20 | testdir::TestDir, | ||
21 | }; | ||
19 | 22 | ||
20 | const PROFILE: &str = ""; | 23 | const 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 | }; |
20 | use serde::Serialize; | 20 | use serde::Serialize; |
21 | use serde_json::{to_string_pretty, Value}; | 21 | use serde_json::{to_string_pretty, Value}; |
22 | use tempfile::TempDir; | ||
23 | use test_utils::{find_mismatch, Fixture}; | 22 | use test_utils::{find_mismatch, Fixture}; |
24 | use vfs::AbsPathBuf; | 23 | use vfs::AbsPathBuf; |
25 | 24 | ||
25 | use crate::testdir::TestDir; | ||
26 | |||
26 | pub struct Project<'a> { | 27 | pub 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 | ||
118 | impl Server { | 119 | impl 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 @@ | |||
1 | use std::{ | ||
2 | fs, io, | ||
3 | path::{Path, PathBuf}, | ||
4 | sync::atomic::{AtomicUsize, Ordering}, | ||
5 | }; | ||
6 | |||
7 | pub struct TestDir { | ||
8 | path: PathBuf, | ||
9 | keep: bool, | ||
10 | } | ||
11 | |||
12 | impl 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 | |||
39 | impl 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))] | ||
49 | fn remove_dir_all(path: &Path) -> io::Result<()> { | ||
50 | fs::remove_dir_all(path) | ||
51 | } | ||
52 | |||
53 | #[cfg(windows)] | ||
54 | fn 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 | } | ||