3 use std::path::{Path, PathBuf};
7 // The maximum length allowed for stderr files.
9 // We limit this because small files are easier to deal with than bigger files.
10 const LENGTH_LIMIT: usize = 200;
13 let exceeding_files: Vec<_> = exceeding_stderr_files();
15 if !exceeding_files.is_empty() {
16 eprintln!("Error: stderr files exceeding limit of {} lines:", LENGTH_LIMIT);
17 for path in exceeding_files {
18 println!("{}", path.display());
20 std::process::exit(1);
24 fn exceeding_stderr_files() -> Vec<PathBuf> {
25 // We use `WalkDir` instead of `fs::read_dir` here in order to recurse into subdirectories.
26 WalkDir::new("../tests/ui")
28 .filter_map(Result::ok)
30 let p = e.into_path();
31 if p.extension() == Some(OsStr::new("stderr")) && count_linenumbers(&p) > LENGTH_LIMIT {
41 fn count_linenumbers(filepath: &Path) -> usize {
42 match fs::read(filepath) {
43 Ok(content) => bytecount::count(&content, b'\n'),
45 eprintln!("Failed to read file: {}", e);