about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJieyou Xu <jieyouxu@outlook.com>2025-08-02 16:09:10 +0800
committerJieyou Xu <jieyouxu@outlook.com>2025-08-02 16:17:44 +0800
commita71428825a3322d2662efdc4299f9cfac3e3f5e5 (patch)
tree832964a1b1974ae5c70e5e66f8cbd6aca1e2cf81
parentc10dc999f004aa04d29652f6fa9dc9535cb10899 (diff)
downloadrust-a71428825a3322d2662efdc4299f9cfac3e3f5e5.tar.gz
rust-a71428825a3322d2662efdc4299f9cfac3e3f5e5.zip
Pull out non-descriptive test name check to own function
-rw-r--r--src/tools/tidy/src/ui_tests.rs60
1 files changed, 39 insertions, 21 deletions
diff --git a/src/tools/tidy/src/ui_tests.rs b/src/tools/tidy/src/ui_tests.rs
index ee26e81c97f..98a6b466ae9 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],
+            );
+        }
+    }
+}