Make ui_tests
non-quadratic
Previously, it would walk each directory twice: once in the main `Walk` iterator, and once to count the number of entries in the directory. Now it only walks each directory once.
This commit is contained in:
parent
9b606a3203
commit
d26a15563d
@ -3,23 +3,29 @@
|
|||||||
//! - there are no stray `.stderr` files
|
//! - there are no stray `.stderr` files
|
||||||
|
|
||||||
use ignore::Walk;
|
use ignore::Walk;
|
||||||
use ignore::WalkBuilder;
|
use std::collections::HashMap;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::Path;
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
const ENTRY_LIMIT: usize = 1000;
|
const ENTRY_LIMIT: usize = 1000;
|
||||||
// FIXME: The following limits should be reduced eventually.
|
// FIXME: The following limits should be reduced eventually.
|
||||||
const ROOT_ENTRY_LIMIT: usize = 940;
|
const ROOT_ENTRY_LIMIT: usize = 940;
|
||||||
const ISSUES_ENTRY_LIMIT: usize = 1978;
|
const ISSUES_ENTRY_LIMIT: usize = 1978;
|
||||||
|
|
||||||
fn check_entries(path: &Path, bad: &mut bool) {
|
fn check_entries(tests_path: &Path, bad: &mut bool) {
|
||||||
for dir in Walk::new(&path.join("ui")) {
|
let mut directories: HashMap<PathBuf, usize> = HashMap::new();
|
||||||
|
|
||||||
|
for dir in Walk::new(&tests_path.join("ui")) {
|
||||||
if let Ok(entry) = dir {
|
if let Ok(entry) = dir {
|
||||||
if entry.file_type().map(|ft| ft.is_dir()).unwrap_or(false) {
|
let parent = entry.path().parent().unwrap().to_path_buf();
|
||||||
let dir_path = entry.path();
|
*directories.entry(parent).or_default() += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (dir_path, count) in directories {
|
||||||
// Use special values for these dirs.
|
// Use special values for these dirs.
|
||||||
let is_root = path.join("ui") == dir_path;
|
let is_root = tests_path.join("ui") == dir_path;
|
||||||
let is_issues_dir = path.join("ui/issues") == dir_path;
|
let is_issues_dir = tests_path.join("ui/issues") == dir_path;
|
||||||
let limit = if is_root {
|
let limit = if is_root {
|
||||||
ROOT_ENTRY_LIMIT
|
ROOT_ENTRY_LIMIT
|
||||||
} else if is_issues_dir {
|
} else if is_issues_dir {
|
||||||
@ -28,14 +34,6 @@ fn check_entries(path: &Path, bad: &mut bool) {
|
|||||||
ENTRY_LIMIT
|
ENTRY_LIMIT
|
||||||
};
|
};
|
||||||
|
|
||||||
let count = WalkBuilder::new(&dir_path)
|
|
||||||
.max_depth(Some(1))
|
|
||||||
.build()
|
|
||||||
.into_iter()
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.len()
|
|
||||||
- 1; // remove the dir itself
|
|
||||||
|
|
||||||
if count > limit {
|
if count > limit {
|
||||||
tidy_error!(
|
tidy_error!(
|
||||||
bad,
|
bad,
|
||||||
@ -48,8 +46,6 @@ fn check_entries(path: &Path, bad: &mut bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn check(path: &Path, bad: &mut bool) {
|
pub fn check(path: &Path, bad: &mut bool) {
|
||||||
check_entries(&path, bad);
|
check_entries(&path, bad);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user