Skip to content

Commit

Permalink
fix target dir test
Browse files Browse the repository at this point in the history
  • Loading branch information
jyn514 committed Feb 9, 2025
1 parent 9bd9bcf commit d2459e5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
);
}

Expand Down
9 changes: 8 additions & 1 deletion src/tools/rust-analyzer/crates/test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit d2459e5

Please sign in to comment.