diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 02468631bc..bceca2b0fb 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -859,7 +859,7 @@ fn manual(fields: &[(&'static str, &'static str, &[&str], &str)]) -> String { mod tests { use std::fs; - use test_utils::{ensure_file_contents, project_dir}; + use test_utils::{ensure_file_contents, project_root}; use super::*; @@ -877,7 +877,7 @@ mod tests { .to_string(); schema.push_str(",\n"); - let package_json_path = project_dir().join("editors/code/package.json"); + let package_json_path = project_root().join("editors/code/package.json"); let mut package_json = fs::read_to_string(&package_json_path).unwrap(); let start_marker = " \"$generated-start\": false,\n"; @@ -896,7 +896,7 @@ mod tests { #[test] fn schema_in_sync_with_docs() { - let docs_path = project_dir().join("docs/user/generated_config.adoc"); + let docs_path = project_root().join("docs/user/generated_config.adoc"); let current = fs::read_to_string(&docs_path).unwrap(); let expected = ConfigData::manual(); diff --git a/crates/syntax/src/tests.rs b/crates/syntax/src/tests.rs index b2c06e24fb..ba0ccfaed1 100644 --- a/crates/syntax/src/tests.rs +++ b/crates/syntax/src/tests.rs @@ -7,7 +7,7 @@ use std::{ use ast::NameOwner; use expect_test::expect_file; use rayon::prelude::*; -use test_utils::{bench, bench_fixture, project_dir, skip_slow_tests}; +use test_utils::{bench, bench_fixture, project_root, skip_slow_tests}; use crate::{ast, fuzz, tokenize, AstNode, SourceFile, SyntaxError, TextRange, TextSize, Token}; @@ -153,7 +153,7 @@ fn reparse_fuzz_tests() { /// Test that Rust-analyzer can parse and validate the rust-analyzer #[test] fn self_hosting_parsing() { - let dir = project_dir().join("crates"); + let dir = project_root().join("crates"); let files = walkdir::WalkDir::new(dir) .into_iter() .filter_entry(|entry| { @@ -193,7 +193,7 @@ fn self_hosting_parsing() { } fn test_data_dir() -> PathBuf { - project_dir().join("crates/syntax/test_data") + project_root().join("crates/syntax/test_data") } fn assert_errors_are_present(errors: &[SyntaxError], path: &Path) { diff --git a/crates/test_utils/src/bench_fixture.rs b/crates/test_utils/src/bench_fixture.rs index d775e2cc9d..3a37c4473c 100644 --- a/crates/test_utils/src/bench_fixture.rs +++ b/crates/test_utils/src/bench_fixture.rs @@ -4,7 +4,7 @@ use std::fs; use stdx::format_to; -use crate::project_dir; +use crate::project_root; pub fn big_struct() -> String { let n = 1_000; @@ -32,11 +32,11 @@ struct S{} {{ } pub fn glorious_old_parser() -> String { - let path = project_dir().join("bench_data/glorious_old_parser"); + let path = project_root().join("bench_data/glorious_old_parser"); fs::read_to_string(&path).unwrap() } pub fn numerous_macro_rules() -> String { - let path = project_dir().join("bench_data/numerous_macro_rules"); + let path = project_root().join("bench_data/numerous_macro_rules"); fs::read_to_string(&path).unwrap() } diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs index 7f122b13eb..097a541393 100644 --- a/crates/test_utils/src/lib.rs +++ b/crates/test_utils/src/lib.rs @@ -288,14 +288,14 @@ pub fn skip_slow_tests() -> bool { if should_skip { eprintln!("ignoring slow test") } else { - let path = project_dir().join("./target/.slow_tests_cookie"); + let path = project_root().join("./target/.slow_tests_cookie"); fs::write(&path, ".").unwrap(); } should_skip } /// Returns the path to the root directory of `rust-analyzer` project. -pub fn project_dir() -> PathBuf { +pub fn project_root() -> PathBuf { let dir = env!("CARGO_MANIFEST_DIR"); PathBuf::from(dir).parent().unwrap().parent().unwrap().to_owned() } @@ -371,7 +371,7 @@ pub fn try_ensure_file_contents(file: &Path, contents: &str) -> Result<(), ()> { } _ => (), } - let display_path = file.strip_prefix(&project_dir()).unwrap_or(file); + let display_path = file.strip_prefix(&project_root()).unwrap_or(file); eprintln!( "\n\x1b[31;1merror\x1b[0m: {} was not up-to-date, updating\n", display_path.display()