Skip to content

Commit 3b05e93

Browse files
committed
Fix parser inline tests codegen panics
When running `cargo codegen` the cwd="rust-analyzer" however when running `cargo test` the cwd="rust-analyzer/xtask" which makes the codegen panic
1 parent da06b7c commit 3b05e93

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

src/tools/rust-analyzer/xtask/src/codegen/parser_inline_tests.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,21 @@ use crate::{
1818
util::list_rust_files,
1919
};
2020

21-
const PARSER_CRATE_ROOT: &str = "crates/parser";
22-
const PARSER_TEST_DATA: &str = "crates/parser/test_data";
23-
const PARSER_TEST_DATA_INLINE: &str = "crates/parser/test_data/parser/inline";
24-
2521
pub(crate) fn generate(check: bool) {
26-
let tests = tests_from_dir(
27-
&project_root().join(Path::new(&format!("{PARSER_CRATE_ROOT}/src/grammar"))),
28-
);
22+
let parser_crate_root = project_root().join("crates/parser");
23+
let parser_test_data = parser_crate_root.join("test_data");
24+
let parser_test_data_inline = parser_test_data.join("parser/inline");
25+
26+
let tests = tests_from_dir(&parser_crate_root.join("src/grammar"));
2927

3028
let mut some_file_was_updated = false;
3129
some_file_was_updated |=
32-
install_tests(&tests.ok, &format!("{PARSER_TEST_DATA_INLINE}/ok"), check).unwrap();
30+
install_tests(&tests.ok, parser_test_data_inline.join("ok"), check).unwrap();
3331
some_file_was_updated |=
34-
install_tests(&tests.err, &format!("{PARSER_TEST_DATA_INLINE}/err"), check).unwrap();
32+
install_tests(&tests.err, parser_test_data_inline.join("err"), check).unwrap();
3533

3634
if some_file_was_updated {
37-
let _ = fs::File::open(format!("{PARSER_CRATE_ROOT}/src/tests.rs"))
35+
let _ = fs::File::open(parser_crate_root.join("src/tests.rs"))
3836
.unwrap()
3937
.set_modified(SystemTime::now());
4038

@@ -95,15 +93,14 @@ pub(crate) fn generate(check: bool) {
9593
let pretty = reformat(output.to_string());
9694
ensure_file_contents(
9795
crate::flags::CodegenType::ParserTests,
98-
format!("{PARSER_TEST_DATA}/generated/runner.rs").as_ref(),
96+
parser_test_data.join("generated/runner.rs").as_ref(),
9997
&pretty,
10098
check,
10199
);
102100
}
103101
}
104102

105-
fn install_tests(tests: &HashMap<String, Test>, into: &str, check: bool) -> Result<bool> {
106-
let tests_dir = project_root().join(into);
103+
fn install_tests(tests: &HashMap<String, Test>, tests_dir: PathBuf, check: bool) -> Result<bool> {
107104
if !tests_dir.is_dir() {
108105
fs::create_dir_all(&tests_dir)?;
109106
}

0 commit comments

Comments
 (0)