From a71428825a3322d2662efdc4299f9cfac3e3f5e5 Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Sat, 2 Aug 2025 16:09:10 +0800 Subject: [PATCH] Pull out non-descriptive test name check to own function --- src/tools/tidy/src/ui_tests.rs | 60 ++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/src/tools/tidy/src/ui_tests.rs b/src/tools/tidy/src/ui_tests.rs index ee26e81c97f6..98a6b466ae91 100644 --- a/src/tools/tidy/src/ui_tests.rs +++ b/src/tools/tidy/src/ui_tests.rs @@ -58,27 +58,14 @@ pub fn check(root_path: &Path, bless: bool, bad: &mut bool) { check_empty_output_snapshot(bad, file_path); } - if ext == "rs" - && let Some(test_name) = static_regex!(r"^issues?[-_]?(\d{3,})").captures(testname) - { - // these paths are always relative to the passed `path` and always UTF8 - let stripped_path = file_path - .strip_prefix(path) - .unwrap() - .to_str() - .unwrap() - .replace(std::path::MAIN_SEPARATOR_STR, "/"); - - if !remaining_issue_names.remove(stripped_path.as_str()) - && !stripped_path.starts_with("ui/issues/") - { - tidy_error!( - bad, - "file `tests/{stripped_path}` must begin with a descriptive name, consider `{{reason}}-issue-{issue_n}.rs`", - issue_n = &test_name[1], - ); - } - } + deny_new_nondescriptive_test_names( + bad, + path, + &mut remaining_issue_names, + file_path, + testname, + ext, + ); } }); @@ -182,3 +169,34 @@ fn check_empty_output_snapshot(bad: &mut bool, file_path: &Path) { tidy_error!(bad, "Empty file with UI testing output: {:?}", file_path); } } + +fn deny_new_nondescriptive_test_names( + bad: &mut bool, + path: &Path, + remaining_issue_names: &mut BTreeSet<&str>, + file_path: &Path, + testname: &str, + ext: &str, +) { + if ext == "rs" + && let Some(test_name) = static_regex!(r"^issues?[-_]?(\d{3,})").captures(testname) + { + // these paths are always relative to the passed `path` and always UTF8 + let stripped_path = file_path + .strip_prefix(path) + .unwrap() + .to_str() + .unwrap() + .replace(std::path::MAIN_SEPARATOR_STR, "/"); + + if !remaining_issue_names.remove(stripped_path.as_str()) + && !stripped_path.starts_with("ui/issues/") + { + tidy_error!( + bad, + "file `tests/{stripped_path}` must begin with a descriptive name, consider `{{reason}}-issue-{issue_n}.rs`", + issue_n = &test_name[1], + ); + } + } +}