From ba93b4972ff21e63a330003c6a4469315651155b Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Sat, 3 Feb 2024 14:18:58 -0800 Subject: [PATCH] Suggest pattern in meaningful test diagnostic As the reason for tidy failing the test name may seem slightly opaque, provide a suggestion on how to rename the file. There are some tests which merely would require reordering of the name according to the rule. I could modify the diagnostic further to identify those, but doing such would make it prone to bad suggestions. I have opted to trust contributors to recognize the diagnostic is robotic, as the pattern we are linting on is easier to match if we do not speculate on what parts of the name are meaningful: sometimes a word is a reason, but sometimes it is a mere "tag", such as with a pair like: issue-314159265-blue.rs issue-314159265-red.rs Starting them with `red-` and `blue-` means they do not sort together, despite being related, and the color names are still not very descriptive. Recognizing a good name is an open-ended task, though this pair might be: colored-circle-gen-blue.rs colored-circle-gen-red.rs Deciding exactly how to solve this is not the business of tidy, only recognizing a what. --- src/tools/tidy/src/ui_tests.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tools/tidy/src/ui_tests.rs b/src/tools/tidy/src/ui_tests.rs index ccdbf0bfcab..4a3b72dc276 100644 --- a/src/tools/tidy/src/ui_tests.rs +++ b/src/tools/tidy/src/ui_tests.rs @@ -150,17 +150,17 @@ pub fn check(path: &Path, bad: &mut bool) { if ext == "rs" { lazy_static! { static ref ISSUE_NAME_REGEX: Regex = - Regex::new(r"^issues?[-_]?\d{3,}").unwrap(); + Regex::new(r"^issues?[-_]?(\d{3,})").unwrap(); } - if ISSUE_NAME_REGEX.is_match(testname) { + if let Some(test_name) = ISSUE_NAME_REGEX.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(); if !allowed_issue_filenames.remove(stripped_path) { tidy_error!( bad, - "UI test `{}` should use a name that describes the test and link the issue in a comment instead.", - file_path.display(), + "file `{stripped_path}` must begin with a descriptive name, consider `{{reason}}-issue-{issue_n}.rs`", + issue_n = &test_name[1], ); } }