about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-12-14 09:25:00 +0000
committerbors <bors@rust-lang.org>2020-12-14 09:25:00 +0000
commit3c45bff23dfbb13d9d28afe5dba57c028ba156da (patch)
tree4099b2d5a5ee660cb9d29cbc0ad6358041480378
parent331e74014a0a2bf18aae7f02495f97958bf9767d (diff)
parentadda964bb5229a7e7fa21d28c77f7ad71afb9b15 (diff)
downloadrust-3c45bff23dfbb13d9d28afe5dba57c028ba156da.tar.gz
rust-3c45bff23dfbb13d9d28afe5dba57c028ba156da.zip
Auto merge of #79959 - JohnTitor:tidy-entries, r=petrochenkov
Check the number of entries in UI test on tidy

This helps #73494 to be resolved.

r? `@petrochenkov`
-rw-r--r--src/tools/tidy/src/ui_tests.rs44
1 files changed, 43 insertions, 1 deletions
diff --git a/src/tools/tidy/src/ui_tests.rs b/src/tools/tidy/src/ui_tests.rs
index 03f4efea983..72ffdabd522 100644
--- a/src/tools/tidy/src/ui_tests.rs
+++ b/src/tools/tidy/src/ui_tests.rs
@@ -1,9 +1,51 @@
-//! Tidy check to ensure that there are no stray `.stderr` files in UI test directories.
+//! Tidy check to ensure below in UI test directories:
+//! - the number of entries in each directory must be less than `ENTRY_LIMIT`
+//! - there are no stray `.stderr` files
 
 use std::fs;
 use std::path::Path;
 
+const ENTRY_LIMIT: usize = 1000;
+// FIXME: The following limits should be reduced eventually.
+const ROOT_ENTRY_LIMIT: usize = 1580;
+const ISSUES_ENTRY_LIMIT: usize = 2830;
+
+fn check_entries(path: &Path, bad: &mut bool) {
+    let dirs = walkdir::WalkDir::new(&path.join("test/ui"))
+        .into_iter()
+        .filter_entry(|e| e.file_type().is_dir());
+    for dir in dirs {
+        if let Ok(dir) = dir {
+            let dir_path = dir.path();
+
+            // Use special values for these dirs.
+            let is_root = path.join("test/ui") == dir_path;
+            let is_issues_dir = path.join("test/ui/issues") == dir_path;
+            let limit = if is_root {
+                ROOT_ENTRY_LIMIT
+            } else if is_issues_dir {
+                ISSUES_ENTRY_LIMIT
+            } else {
+                ENTRY_LIMIT
+            };
+
+            let count = std::fs::read_dir(dir_path).unwrap().count();
+            if count >= limit {
+                tidy_error!(
+                    bad,
+                    "following path contains more than {} entries, \
+                    you should move the test to some relevant subdirectory (current: {}): {}",
+                    limit,
+                    count,
+                    dir_path.display()
+                );
+            }
+        }
+    }
+}
+
 pub fn check(path: &Path, bad: &mut bool) {
+    check_entries(&path, bad);
     for path in &[&path.join("test/ui"), &path.join("test/ui-fulldeps")] {
         super::walk_no_read(path, &mut |_| false, &mut |entry| {
             let file_path = entry.path();