Skip to content

Commit adda964

Browse files
committed
Check the number of entries in UI test
1 parent 7feab00 commit adda964

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

Diff for: src/tools/tidy/src/ui_tests.rs

+43-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,51 @@
1-
//! Tidy check to ensure that there are no stray `.stderr` files in UI test directories.
1+
//! Tidy check to ensure below in UI test directories:
2+
//! - the number of entries in each directory must be less than `ENTRY_LIMIT`
3+
//! - there are no stray `.stderr` files
24
35
use std::fs;
46
use std::path::Path;
57

8+
const ENTRY_LIMIT: usize = 1000;
9+
// FIXME: The following limits should be reduced eventually.
10+
const ROOT_ENTRY_LIMIT: usize = 1580;
11+
const ISSUES_ENTRY_LIMIT: usize = 2830;
12+
13+
fn check_entries(path: &Path, bad: &mut bool) {
14+
let dirs = walkdir::WalkDir::new(&path.join("test/ui"))
15+
.into_iter()
16+
.filter_entry(|e| e.file_type().is_dir());
17+
for dir in dirs {
18+
if let Ok(dir) = dir {
19+
let dir_path = dir.path();
20+
21+
// Use special values for these dirs.
22+
let is_root = path.join("test/ui") == dir_path;
23+
let is_issues_dir = path.join("test/ui/issues") == dir_path;
24+
let limit = if is_root {
25+
ROOT_ENTRY_LIMIT
26+
} else if is_issues_dir {
27+
ISSUES_ENTRY_LIMIT
28+
} else {
29+
ENTRY_LIMIT
30+
};
31+
32+
let count = std::fs::read_dir(dir_path).unwrap().count();
33+
if count >= limit {
34+
tidy_error!(
35+
bad,
36+
"following path contains more than {} entries, \
37+
you should move the test to some relevant subdirectory (current: {}): {}",
38+
limit,
39+
count,
40+
dir_path.display()
41+
);
42+
}
43+
}
44+
}
45+
}
46+
647
pub fn check(path: &Path, bad: &mut bool) {
48+
check_entries(&path, bad);
749
for path in &[&path.join("test/ui"), &path.join("test/ui-fulldeps")] {
850
super::walk_no_read(path, &mut |_| false, &mut |entry| {
951
let file_path = entry.path();

0 commit comments

Comments
 (0)