22//! - the number of entries in each directory must be less than `ENTRY_LIMIT`
33//! - there are no stray `.stderr` files
44
5+ use ignore:: Walk ;
6+ use ignore:: WalkBuilder ;
57use std:: fs;
68use std:: path:: Path ;
79
@@ -11,34 +13,39 @@ const ROOT_ENTRY_LIMIT: usize = 941;
1113const ISSUES_ENTRY_LIMIT : usize = 2117 ;
1214
1315fn 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+ } ;
2030
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
3138
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+ }
4249 }
4350 }
4451 }
0 commit comments