5 use std::io::prelude::*;
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 LIMIT: usize = 275;
13 let stderr_files = stderr_files();
14 let exceeding_files = exceeding_stderr_files(stderr_files).collect::<Vec<String>>();
16 if !exceeding_files.is_empty() {
17 eprintln!("Error: stderr files exceeding limit of {} lines:", LIMIT);
18 for path in exceeding_files {
21 std::process::exit(1);
25 fn exceeding_stderr_files(files: impl Iterator<Item = walkdir::DirEntry>) -> impl Iterator<Item = String> {
26 files.filter_map(|file| {
27 let path = file.path().to_str().expect("Could not convert path to str").to_string();
28 let linecount = count_linenumbers(&path);
29 if linecount > LIMIT {
37 fn stderr_files() -> impl Iterator<Item = walkdir::DirEntry> {
38 // We use `WalkDir` instead of `fs::read_dir` here in order to recurse into subdirectories.
39 WalkDir::new("../tests/ui")
41 .filter_map(std::result::Result::ok)
42 .filter(|f| f.path().extension() == Some(OsStr::new("stderr")))
45 fn count_linenumbers(filepath: &str) -> usize {
46 if let Ok(mut file) = File::open(filepath) {
47 let mut content = String::new();
48 file.read_to_string(&mut content).expect("Failed to read file?");
49 content.lines().count()