From 14eb786eea13c0be6ef2084bf022fa91e68ae15c Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Tue, 18 Dec 2018 12:53:02 +0100 Subject: [PATCH] tests: Don't generate tooltip results in tests/fixtures --- src/actions/hover.rs | 31 +++++++++---------------------- src/test/harness.rs | 13 +++---------- 2 files changed, 12 insertions(+), 32 deletions(-) diff --git a/src/actions/hover.rs b/src/actions/hover.rs index dde653e4c56..a7df9109807 100644 --- a/src/actions/hover.rs +++ b/src/actions/hover.rs @@ -1191,14 +1191,9 @@ pub mod test { related_information_support: true, }; let mut config = config::Config::default(); - let cur_dir = env::current_dir().unwrap(); - let target_dir = env::var("CARGO_TARGET_DIR") - .map(|s| Path::new(&s).to_owned()) - .unwrap_or_else(|_| cur_dir.join("target")); - let working_dir = target_dir.join("tests").join("hover").join("working_dir"); - - config.target_dir = config::Inferrable::Specified(Some(working_dir.clone())); + let temp_dir = tempfile::tempdir().unwrap().into_path(); + config.target_dir = config::Inferrable::Specified(Some(temp_dir.clone())); let config = Arc::new(Mutex::new(config)); let analysis = Arc::new(analysis::AnalysisHost::new(analysis::Target::Debug)); @@ -1220,7 +1215,7 @@ pub mod test { TooltipTestHarness { ctx, project_dir, - working_dir, + working_dir: temp_dir } } @@ -2056,7 +2051,6 @@ pub mod test { fn test_tooltip() -> Result<(), Box> { let _ = env_logger::try_init(); use self::test::{LineOutput, Test, TooltipTestHarness}; - use std::env; let tests = vec![ Test::new("test_tooltip_01.rs", 13, 11), @@ -2112,14 +2106,11 @@ pub mod test { Test::new("test_tooltip_mod_use_external.rs", 12, 12), ]; - let cwd = env::current_dir()?; let out = LineOutput::default(); let proj_dir = FIXTURES_DIR.join("hover"); - let save_dir = cwd - .join("target") - .join("tests") - .join("hover") - .join("save_data"); + + let save_dir_guard = tempfile::tempdir().unwrap(); + let save_dir = save_dir_guard.path().to_owned(); let load_dir = proj_dir.join("save_data"); let harness = TooltipTestHarness::new(proj_dir, &out); @@ -2145,7 +2136,6 @@ pub mod test { fn test_tooltip_std() -> Result<(), Box> { let _ = env_logger::try_init(); use self::test::{LineOutput, Test, TooltipTestHarness}; - use std::env; let tests = vec![ // these test std stuff @@ -2167,14 +2157,11 @@ pub mod test { Test::new("test_tooltip_std.rs", 25, 25), ]; - let cwd = env::current_dir()?; let out = LineOutput::default(); let proj_dir = FIXTURES_DIR.join("hover"); - let save_dir = cwd - .join("target") - .join("tests") - .join("hover") - .join("save_data"); + + let save_dir_guard = tempfile::tempdir().unwrap(); + let save_dir = save_dir_guard.path().to_owned(); let load_dir = proj_dir.join("save_data"); let harness = TooltipTestHarness::new(proj_dir, &out); diff --git a/src/test/harness.rs b/src/test/harness.rs index b446f60043d..d8170ee8441 100644 --- a/src/test/harness.rs +++ b/src/test/harness.rs @@ -29,7 +29,6 @@ use serde_json; use walkdir::WalkDir; lazy_static! { - static ref COUNTER: AtomicUsize = AtomicUsize::new(0); static ref MANIFEST_DIR: &'static Path = Path::new(env!("CARGO_MANIFEST_DIR")); pub static ref FIXTURES_DIR: PathBuf = MANIFEST_DIR.join("tests").join("fixtures"); } @@ -51,16 +50,10 @@ impl Environment { let scratchpad_dir = build_scratchpad_from_fixture(fixture_dir) .expect("Can't copy fixture files to scratchpad"); - let target_dir = env::var("CARGO_TARGET_DIR") - .map(|s| Path::new(&s).to_owned()) - .unwrap_or_else(|_| MANIFEST_DIR.join("target")); - - let working_dir = target_dir - .join("tests") - .join(format!("{}", COUNTER.fetch_add(1, Ordering::Relaxed))); + let target_dir = scratchpad_dir.join("target"); let mut config = Config::default(); - config.target_dir = Inferrable::Specified(Some(working_dir.clone())); + config.target_dir = Inferrable::Specified(Some(target_dir.clone())); config.unstable_features = true; let cache = Cache::new(scratchpad_dir); @@ -68,7 +61,7 @@ impl Environment { Self { config: Some(config), cache, - target_path: working_dir, + target_path: target_dir, } } }