mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-03 05:13:35 +00:00
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
This commit is contained in:
parent
9df88ff0f6
commit
7236109f56
1 changed files with 10 additions and 13 deletions
|
|
@ -18,23 +18,21 @@ use crate::{
|
||||||
util::list_rust_files,
|
util::list_rust_files,
|
||||||
};
|
};
|
||||||
|
|
||||||
const PARSER_CRATE_ROOT: &str = "crates/parser";
|
|
||||||
const PARSER_TEST_DATA: &str = "crates/parser/test_data";
|
|
||||||
const PARSER_TEST_DATA_INLINE: &str = "crates/parser/test_data/parser/inline";
|
|
||||||
|
|
||||||
pub(crate) fn generate(check: bool) {
|
pub(crate) fn generate(check: bool) {
|
||||||
let tests = tests_from_dir(
|
let parser_crate_root = project_root().join("crates/parser");
|
||||||
&project_root().join(Path::new(&format!("{PARSER_CRATE_ROOT}/src/grammar"))),
|
let parser_test_data = parser_crate_root.join("test_data");
|
||||||
);
|
let parser_test_data_inline = parser_test_data.join("parser/inline");
|
||||||
|
|
||||||
|
let tests = tests_from_dir(&parser_crate_root.join("src/grammar"));
|
||||||
|
|
||||||
let mut some_file_was_updated = false;
|
let mut some_file_was_updated = false;
|
||||||
some_file_was_updated |=
|
some_file_was_updated |=
|
||||||
install_tests(&tests.ok, &format!("{PARSER_TEST_DATA_INLINE}/ok"), check).unwrap();
|
install_tests(&tests.ok, parser_test_data_inline.join("ok"), check).unwrap();
|
||||||
some_file_was_updated |=
|
some_file_was_updated |=
|
||||||
install_tests(&tests.err, &format!("{PARSER_TEST_DATA_INLINE}/err"), check).unwrap();
|
install_tests(&tests.err, parser_test_data_inline.join("err"), check).unwrap();
|
||||||
|
|
||||||
if some_file_was_updated {
|
if some_file_was_updated {
|
||||||
let _ = fs::File::open(format!("{PARSER_CRATE_ROOT}/src/tests.rs"))
|
let _ = fs::File::open(parser_crate_root.join("src/tests.rs"))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.set_modified(SystemTime::now());
|
.set_modified(SystemTime::now());
|
||||||
|
|
||||||
|
|
@ -95,15 +93,14 @@ pub(crate) fn generate(check: bool) {
|
||||||
let pretty = reformat(output.to_string());
|
let pretty = reformat(output.to_string());
|
||||||
ensure_file_contents(
|
ensure_file_contents(
|
||||||
crate::flags::CodegenType::ParserTests,
|
crate::flags::CodegenType::ParserTests,
|
||||||
format!("{PARSER_TEST_DATA}/generated/runner.rs").as_ref(),
|
parser_test_data.join("generated/runner.rs").as_ref(),
|
||||||
&pretty,
|
&pretty,
|
||||||
check,
|
check,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn install_tests(tests: &HashMap<String, Test>, into: &str, check: bool) -> Result<bool> {
|
fn install_tests(tests: &HashMap<String, Test>, tests_dir: PathBuf, check: bool) -> Result<bool> {
|
||||||
let tests_dir = project_root().join(into);
|
|
||||||
if !tests_dir.is_dir() {
|
if !tests_dir.is_dir() {
|
||||||
fs::create_dir_all(&tests_dir)?;
|
fs::create_dir_all(&tests_dir)?;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue