2
2
//! - the number of entries in each directory must be less than `ENTRY_LIMIT`
3
3
//! - there are no stray `.stderr` files
4
4
5
+ use ignore::Walk;
6
+ use ignore::WalkBuilder;
5
7
use std::fs;
6
8
use std::path::Path;
7
9
@@ -11,34 +13,39 @@ const ROOT_ENTRY_LIMIT: usize = 941;
11
13
const ISSUES_ENTRY_LIMIT: usize = 2117;
12
14
13
15
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();
16
+ for dir in Walk::new(&path.join("test/ui")) {
17
+ if let Ok(entry) = dir {
18
+ if entry.file_type().map(|ft| ft.is_dir()).unwrap_or(false) {
19
+ let dir_path = entry.path();
20
+ // Use special values for these dirs.
21
+ let is_root = path.join("test/ui") == dir_path;
22
+ let is_issues_dir = path.join("test/ui/issues") == dir_path;
23
+ let limit = if is_root {
24
+ ROOT_ENTRY_LIMIT
25
+ } else if is_issues_dir {
26
+ ISSUES_ENTRY_LIMIT
27
+ } else {
28
+ ENTRY_LIMIT
29
+ };
20
30
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
+ let count = WalkBuilder::new(&dir_path)
32
+ .max_depth(Some(1))
33
+ .build()
34
+ .into_iter()
35
+ .collect::<Vec<_>>()
36
+ .len()
37
+ - 1; // remove the dir itself
31
38
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
- );
39
+ if count > limit {
40
+ tidy_error!(
41
+ bad,
42
+ "following path contains more than {} entries, \
43
+ you should move the test to some relevant subdirectory (current: {}): {}",
44
+ limit ,
45
+ count ,
46
+ dir_path.display()
47
+ );
48
+ }
42
49
}
43
50
}
44
51
}
0 commit comments