Fix limit-stderr-files test

This commit is contained in:
flip1995 2020-03-18 15:27:25 +01:00
parent a808779441
commit f041dcdb4e
No known key found for this signature in database
GPG key ID: 2CEFCDB27ED0BE79

View file

@ -4,6 +4,8 @@ use std::path::{Path, PathBuf};
use walkdir::WalkDir;
use clippy_dev::clippy_project_root;
// The maximum length allowed for stderr files.
//
// We limit this because small files are easier to deal with than bigger files.
@ -14,22 +16,24 @@ pub fn check() {
if !exceeding_files.is_empty() {
eprintln!("Error: stderr files exceeding limit of {} lines:", LENGTH_LIMIT);
for path in exceeding_files {
println!("{}", path.display());
for (path, count) in exceeding_files {
println!("{}: {}", path.display(), count);
}
std::process::exit(1);
}
}
fn exceeding_stderr_files() -> Vec<PathBuf> {
fn exceeding_stderr_files() -> Vec<(PathBuf, usize)> {
// We use `WalkDir` instead of `fs::read_dir` here in order to recurse into subdirectories.
WalkDir::new("../tests/ui")
WalkDir::new(clippy_project_root().join("tests/ui"))
.into_iter()
.filter_map(Result::ok)
.filter(|f| !f.file_type().is_dir())
.filter_map(|e| {
let p = e.into_path();
if p.extension() == Some(OsStr::new("stderr")) && count_linenumbers(&p) > LENGTH_LIMIT {
Some(p)
let count = count_linenumbers(&p);
if p.extension() == Some(OsStr::new("stderr")) && count > LENGTH_LIMIT {
Some((p, count))
} else {
None
}