Skip to content

Commit 18511ba

Browse files
committed
test tidy should not count untracked paths towards entries limit
1 parent 126dbdc commit 18511ba

File tree

3 files changed

+35
-26
lines changed

3 files changed

+35
-26
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4919,6 +4919,7 @@ name = "tidy"
49194919
version = "0.1.0"
49204920
dependencies = [
49214921
"cargo_metadata 0.14.0",
4922+
"ignore",
49224923
"lazy_static",
49234924
"regex",
49244925
"walkdir",

src/tools/tidy/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ cargo_metadata = "0.14"
99
regex = "1"
1010
lazy_static = "1"
1111
walkdir = "2"
12+
ignore = "0.4.18"
1213

1314
[[bin]]
1415
name = "rust-tidy"

src/tools/tidy/src/ui_tests.rs

+33-26
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
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;
57
use std::fs;
68
use std::path::Path;
79

@@ -11,34 +13,39 @@ const ROOT_ENTRY_LIMIT: usize = 948;
1113
const ISSUES_ENTRY_LIMIT: usize = 2117;
1214

1315
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+
};
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

Comments
 (0)