Skip to content

Commit 82d7de8

Browse files
authored
Rollup merge of #103958 - chenyukang:yukang/fix-103951-count-limit, r=jyn514
Test tidy should not count untracked paths towards entries limit Fixes #103951 r? `@jyn514`
2 parents f7ed72d + 18511ba commit 82d7de8

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
@@ -4937,6 +4937,7 @@ name = "tidy"
49374937
version = "0.1.0"
49384938
dependencies = [
49394939
"cargo_metadata 0.14.0",
4940+
"ignore",
49404941
"lazy_static",
49414942
"miropt-test-tools",
49424943
"regex",

src/tools/tidy/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ regex = "1"
1010
miropt-test-tools = { path = "../miropt-test-tools" }
1111
lazy_static = "1"
1212
walkdir = "2"
13+
ignore = "0.4.18"
1314

1415
[[bin]]
1516
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 = 941;
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)