diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index e915e55722..2e9bb8c08e 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -3798,8 +3798,10 @@ mod tests { (config, _, _) = config.apply_change(change); assert_eq!(config.cargo_targetDir(None), &Some(TargetDirectory::UseSubdirectory(true))); + let target = + Utf8PathBuf::from(std::env::var("CARGO_TARGET_DIR").unwrap_or("target".to_owned())); assert!( - matches!(config.flycheck(None), FlycheckConfig::CargoCommand { options, .. } if options.target_dir == Some(Utf8PathBuf::from("target/rust-analyzer"))) + matches!(config.flycheck(None), FlycheckConfig::CargoCommand { options, .. } if options.target_dir == Some(target.join("rust-analyzer"))) ); } diff --git a/crates/test-utils/src/lib.rs b/crates/test-utils/src/lib.rs index 36be9937d3..e7279fa1f6 100644 --- a/crates/test-utils/src/lib.rs +++ b/crates/test-utils/src/lib.rs @@ -396,12 +396,19 @@ pub fn skip_slow_tests() -> bool { if should_skip { eprintln!("ignoring slow test"); } else { - let path = project_root().join("./target/.slow_tests_cookie"); + let path = target_dir().join(".slow_tests_cookie"); fs::write(path, ".").unwrap(); } should_skip } +pub fn target_dir() -> Utf8PathBuf { + match std::env::var("CARGO_TARGET_DIR") { + Ok(target) => Utf8PathBuf::from(target), + Err(_) => project_root().join("target"), + } +} + /// Returns the path to the root directory of `rust-analyzer` project. pub fn project_root() -> Utf8PathBuf { let dir = env!("CARGO_MANIFEST_DIR");