mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-14 01:41:26 +00:00
Fix codegen of parser inline tests runner
When running `cargo codegen` the `crates/parser/test_data/generated/runner.rs` file is only updated when some file in `crates/parser/test_data/inline` changes. However this is not sufficient in all cases
This commit is contained in:
parent
7236109f56
commit
18d6e281b3
2 changed files with 64 additions and 66 deletions
|
|
@ -721,16 +721,16 @@ mod err {
|
||||||
#[test]
|
#[test]
|
||||||
fn bad_asm_expr() { run_and_expect_errors("test_data/parser/inline/err/bad_asm_expr.rs"); }
|
fn bad_asm_expr() { run_and_expect_errors("test_data/parser/inline/err/bad_asm_expr.rs"); }
|
||||||
#[test]
|
#[test]
|
||||||
|
fn comma_after_default_values_syntax() {
|
||||||
|
run_and_expect_errors("test_data/parser/inline/err/comma_after_default_values_syntax.rs");
|
||||||
|
}
|
||||||
|
#[test]
|
||||||
fn comma_after_functional_update_syntax() {
|
fn comma_after_functional_update_syntax() {
|
||||||
run_and_expect_errors(
|
run_and_expect_errors(
|
||||||
"test_data/parser/inline/err/comma_after_functional_update_syntax.rs",
|
"test_data/parser/inline/err/comma_after_functional_update_syntax.rs",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn comma_after_default_values_syntax() {
|
|
||||||
run_and_expect_errors("test_data/parser/inline/err/comma_after_default_values_syntax.rs");
|
|
||||||
}
|
|
||||||
#[test]
|
|
||||||
fn crate_visibility_empty_recover() {
|
fn crate_visibility_empty_recover() {
|
||||||
run_and_expect_errors("test_data/parser/inline/err/crate_visibility_empty_recover.rs");
|
run_and_expect_errors("test_data/parser/inline/err/crate_visibility_empty_recover.rs");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,69 +35,67 @@ pub(crate) fn generate(check: bool) {
|
||||||
let _ = fs::File::open(parser_crate_root.join("src/tests.rs"))
|
let _ = fs::File::open(parser_crate_root.join("src/tests.rs"))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.set_modified(SystemTime::now());
|
.set_modified(SystemTime::now());
|
||||||
|
|
||||||
let ok_tests = tests.ok.values().sorted_by(|a, b| a.name.cmp(&b.name)).map(|test| {
|
|
||||||
let test_name = quote::format_ident!("{}", test.name);
|
|
||||||
let test_file = format!("test_data/parser/inline/ok/{test_name}.rs");
|
|
||||||
let (test_func, args) = match &test.edition {
|
|
||||||
Some(edition) => {
|
|
||||||
let edition = quote::format_ident!("Edition{edition}");
|
|
||||||
(
|
|
||||||
quote::format_ident!("run_and_expect_no_errors_with_edition"),
|
|
||||||
quote::quote! {#test_file, crate::Edition::#edition},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
(quote::format_ident!("run_and_expect_no_errors"), quote::quote! {#test_file})
|
|
||||||
}
|
|
||||||
};
|
|
||||||
quote::quote! {
|
|
||||||
#[test]
|
|
||||||
fn #test_name() {
|
|
||||||
#test_func(#args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
let err_tests = tests.err.values().sorted_by(|a, b| a.name.cmp(&b.name)).map(|test| {
|
|
||||||
let test_name = quote::format_ident!("{}", test.name);
|
|
||||||
let test_file = format!("test_data/parser/inline/err/{test_name}.rs");
|
|
||||||
let (test_func, args) = match &test.edition {
|
|
||||||
Some(edition) => {
|
|
||||||
let edition = quote::format_ident!("Edition{edition}");
|
|
||||||
(
|
|
||||||
quote::format_ident!("run_and_expect_errors_with_edition"),
|
|
||||||
quote::quote! {#test_file, crate::Edition::#edition},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
None => (quote::format_ident!("run_and_expect_errors"), quote::quote! {#test_file}),
|
|
||||||
};
|
|
||||||
quote::quote! {
|
|
||||||
#[test]
|
|
||||||
fn #test_name() {
|
|
||||||
#test_func(#args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let output = quote::quote! {
|
|
||||||
mod ok {
|
|
||||||
use crate::tests::*;
|
|
||||||
#(#ok_tests)*
|
|
||||||
}
|
|
||||||
mod err {
|
|
||||||
use crate::tests::*;
|
|
||||||
#(#err_tests)*
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let pretty = reformat(output.to_string());
|
|
||||||
ensure_file_contents(
|
|
||||||
crate::flags::CodegenType::ParserTests,
|
|
||||||
parser_test_data.join("generated/runner.rs").as_ref(),
|
|
||||||
&pretty,
|
|
||||||
check,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let ok_tests = tests.ok.values().sorted_by(|a, b| a.name.cmp(&b.name)).map(|test| {
|
||||||
|
let test_name = quote::format_ident!("{}", test.name);
|
||||||
|
let test_file = format!("test_data/parser/inline/ok/{test_name}.rs");
|
||||||
|
let (test_func, args) = match &test.edition {
|
||||||
|
Some(edition) => {
|
||||||
|
let edition = quote::format_ident!("Edition{edition}");
|
||||||
|
(
|
||||||
|
quote::format_ident!("run_and_expect_no_errors_with_edition"),
|
||||||
|
quote::quote! {#test_file, crate::Edition::#edition},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
None => (quote::format_ident!("run_and_expect_no_errors"), quote::quote! {#test_file}),
|
||||||
|
};
|
||||||
|
quote::quote! {
|
||||||
|
#[test]
|
||||||
|
fn #test_name() {
|
||||||
|
#test_func(#args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let err_tests = tests.err.values().sorted_by(|a, b| a.name.cmp(&b.name)).map(|test| {
|
||||||
|
let test_name = quote::format_ident!("{}", test.name);
|
||||||
|
let test_file = format!("test_data/parser/inline/err/{test_name}.rs");
|
||||||
|
let (test_func, args) = match &test.edition {
|
||||||
|
Some(edition) => {
|
||||||
|
let edition = quote::format_ident!("Edition{edition}");
|
||||||
|
(
|
||||||
|
quote::format_ident!("run_and_expect_errors_with_edition"),
|
||||||
|
quote::quote! {#test_file, crate::Edition::#edition},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
None => (quote::format_ident!("run_and_expect_errors"), quote::quote! {#test_file}),
|
||||||
|
};
|
||||||
|
quote::quote! {
|
||||||
|
#[test]
|
||||||
|
fn #test_name() {
|
||||||
|
#test_func(#args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let output = quote::quote! {
|
||||||
|
mod ok {
|
||||||
|
use crate::tests::*;
|
||||||
|
#(#ok_tests)*
|
||||||
|
}
|
||||||
|
mod err {
|
||||||
|
use crate::tests::*;
|
||||||
|
#(#err_tests)*
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let pretty = reformat(output.to_string());
|
||||||
|
ensure_file_contents(
|
||||||
|
crate::flags::CodegenType::ParserTests,
|
||||||
|
parser_test_data.join("generated/runner.rs").as_ref(),
|
||||||
|
&pretty,
|
||||||
|
check,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn install_tests(tests: &HashMap<String, Test>, tests_dir: PathBuf, check: bool) -> Result<bool> {
|
fn install_tests(tests: &HashMap<String, Test>, tests_dir: PathBuf, check: bool) -> Result<bool> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue