Skip to content

Commit 563435e

Browse files
committed
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
1 parent 3b05e93 commit 563435e

File tree

2 files changed

+59
-61
lines changed

2 files changed

+59
-61
lines changed

Diff for: src/tools/rust-analyzer/crates/parser/test_data/generated/runner.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -721,16 +721,16 @@ mod err {
721721
#[test]
722722
fn bad_asm_expr() { run_and_expect_errors("test_data/parser/inline/err/bad_asm_expr.rs"); }
723723
#[test]
724+
fn comma_after_default_values_syntax() {
725+
run_and_expect_errors("test_data/parser/inline/err/comma_after_default_values_syntax.rs");
726+
}
727+
#[test]
724728
fn comma_after_functional_update_syntax() {
725729
run_and_expect_errors(
726730
"test_data/parser/inline/err/comma_after_functional_update_syntax.rs",
727731
);
728732
}
729733
#[test]
730-
fn comma_after_default_values_syntax() {
731-
run_and_expect_errors("test_data/parser/inline/err/comma_after_default_values_syntax.rs");
732-
}
733-
#[test]
734734
fn crate_visibility_empty_recover() {
735735
run_and_expect_errors("test_data/parser/inline/err/crate_visibility_empty_recover.rs");
736736
}

Diff for: src/tools/rust-analyzer/xtask/src/codegen/parser_inline_tests.rs

+55-57
Original file line numberDiff line numberDiff line change
@@ -35,69 +35,67 @@ pub(crate) fn generate(check: bool) {
3535
let _ = fs::File::open(parser_crate_root.join("src/tests.rs"))
3636
.unwrap()
3737
.set_modified(SystemTime::now());
38+
}
3839

39-
let ok_tests = tests.ok.values().sorted_by(|a, b| a.name.cmp(&b.name)).map(|test| {
40-
let test_name = quote::format_ident!("{}", test.name);
41-
let test_file = format!("test_data/parser/inline/ok/{test_name}.rs");
42-
let (test_func, args) = match &test.edition {
43-
Some(edition) => {
44-
let edition = quote::format_ident!("Edition{edition}");
45-
(
46-
quote::format_ident!("run_and_expect_no_errors_with_edition"),
47-
quote::quote! {#test_file, crate::Edition::#edition},
48-
)
49-
}
50-
None => {
51-
(quote::format_ident!("run_and_expect_no_errors"), quote::quote! {#test_file})
52-
}
53-
};
54-
quote::quote! {
55-
#[test]
56-
fn #test_name() {
57-
#test_func(#args);
58-
}
40+
let ok_tests = tests.ok.values().sorted_by(|a, b| a.name.cmp(&b.name)).map(|test| {
41+
let test_name = quote::format_ident!("{}", test.name);
42+
let test_file = format!("test_data/parser/inline/ok/{test_name}.rs");
43+
let (test_func, args) = match &test.edition {
44+
Some(edition) => {
45+
let edition = quote::format_ident!("Edition{edition}");
46+
(
47+
quote::format_ident!("run_and_expect_no_errors_with_edition"),
48+
quote::quote! {#test_file, crate::Edition::#edition},
49+
)
5950
}
60-
});
61-
let err_tests = tests.err.values().sorted_by(|a, b| a.name.cmp(&b.name)).map(|test| {
62-
let test_name = quote::format_ident!("{}", test.name);
63-
let test_file = format!("test_data/parser/inline/err/{test_name}.rs");
64-
let (test_func, args) = match &test.edition {
65-
Some(edition) => {
66-
let edition = quote::format_ident!("Edition{edition}");
67-
(
68-
quote::format_ident!("run_and_expect_errors_with_edition"),
69-
quote::quote! {#test_file, crate::Edition::#edition},
70-
)
71-
}
72-
None => (quote::format_ident!("run_and_expect_errors"), quote::quote! {#test_file}),
73-
};
74-
quote::quote! {
75-
#[test]
76-
fn #test_name() {
77-
#test_func(#args);
78-
}
79-
}
80-
});
81-
82-
let output = quote::quote! {
83-
mod ok {
84-
use crate::tests::*;
85-
#(#ok_tests)*
51+
None => (quote::format_ident!("run_and_expect_no_errors"), quote::quote! {#test_file}),
52+
};
53+
quote::quote! {
54+
#[test]
55+
fn #test_name() {
56+
#test_func(#args);
8657
}
87-
mod err {
88-
use crate::tests::*;
89-
#(#err_tests)*
58+
}
59+
});
60+
let err_tests = tests.err.values().sorted_by(|a, b| a.name.cmp(&b.name)).map(|test| {
61+
let test_name = quote::format_ident!("{}", test.name);
62+
let test_file = format!("test_data/parser/inline/err/{test_name}.rs");
63+
let (test_func, args) = match &test.edition {
64+
Some(edition) => {
65+
let edition = quote::format_ident!("Edition{edition}");
66+
(
67+
quote::format_ident!("run_and_expect_errors_with_edition"),
68+
quote::quote! {#test_file, crate::Edition::#edition},
69+
)
9070
}
71+
None => (quote::format_ident!("run_and_expect_errors"), quote::quote! {#test_file}),
9172
};
73+
quote::quote! {
74+
#[test]
75+
fn #test_name() {
76+
#test_func(#args);
77+
}
78+
}
79+
});
9280

93-
let pretty = reformat(output.to_string());
94-
ensure_file_contents(
95-
crate::flags::CodegenType::ParserTests,
96-
parser_test_data.join("generated/runner.rs").as_ref(),
97-
&pretty,
98-
check,
99-
);
100-
}
81+
let output = quote::quote! {
82+
mod ok {
83+
use crate::tests::*;
84+
#(#ok_tests)*
85+
}
86+
mod err {
87+
use crate::tests::*;
88+
#(#err_tests)*
89+
}
90+
};
91+
92+
let pretty = reformat(output.to_string());
93+
ensure_file_contents(
94+
crate::flags::CodegenType::ParserTests,
95+
parser_test_data.join("generated/runner.rs").as_ref(),
96+
&pretty,
97+
check,
98+
);
10199
}
102100

103101
fn install_tests(tests: &HashMap<String, Test>, tests_dir: PathBuf, check: bool) -> Result<bool> {

0 commit comments

Comments
 (0)