|
3 | 3 | //! - there are no stray `.stderr` files
|
4 | 4 |
|
5 | 5 | use ignore::Walk;
|
6 |
| -use ignore::WalkBuilder; |
| 6 | +use std::collections::HashMap; |
7 | 7 | use std::fs;
|
8 |
| -use std::path::Path; |
| 8 | +use std::path::{Path, PathBuf}; |
9 | 9 |
|
10 | 10 | const ENTRY_LIMIT: usize = 1000;
|
11 | 11 | // FIXME: The following limits should be reduced eventually.
|
12 | 12 | const ROOT_ENTRY_LIMIT: usize = 940;
|
13 | 13 | const ISSUES_ENTRY_LIMIT: usize = 1978;
|
14 | 14 |
|
15 |
| -fn check_entries(path: &Path, bad: &mut bool) { |
16 |
| - for dir in Walk::new(&path.join("ui")) { |
| 15 | +fn check_entries(tests_path: &Path, bad: &mut bool) { |
| 16 | + let mut directories: HashMap<PathBuf, usize> = HashMap::new(); |
| 17 | + |
| 18 | + for dir in Walk::new(&tests_path.join("ui")) { |
17 | 19 | 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("ui") == dir_path; |
22 |
| - let is_issues_dir = path.join("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 | + let parent = entry.path().parent().unwrap().to_path_buf(); |
| 21 | + *directories.entry(parent).or_default() += 1; |
| 22 | + } |
| 23 | + } |
30 | 24 |
|
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 |
| 25 | + for (dir_path, count) in directories { |
| 26 | + // Use special values for these dirs. |
| 27 | + let is_root = tests_path.join("ui") == dir_path; |
| 28 | + let is_issues_dir = tests_path.join("ui/issues") == dir_path; |
| 29 | + let limit = if is_root { |
| 30 | + ROOT_ENTRY_LIMIT |
| 31 | + } else if is_issues_dir { |
| 32 | + ISSUES_ENTRY_LIMIT |
| 33 | + } else { |
| 34 | + ENTRY_LIMIT |
| 35 | + }; |
38 | 36 |
|
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 |
| - } |
49 |
| - } |
| 37 | + if count > limit { |
| 38 | + tidy_error!( |
| 39 | + bad, |
| 40 | + "following path contains more than {} entries, \ |
| 41 | + you should move the test to some relevant subdirectory (current: {}): {}", |
| 42 | + limit, |
| 43 | + count, |
| 44 | + dir_path.display() |
| 45 | + ); |
50 | 46 | }
|
51 | 47 | }
|
52 | 48 | }
|
|
0 commit comments