// Take a look at the license at the top of the repository in the LICENSE file. use std::fs::{self, File}; use std::io::Read; use std::path::Path; pub struct TestResult { pub nb_tests: usize, pub nb_errors: usize, } impl std::ops::AddAssign for TestResult { fn add_assign(&mut self, other: Self) { self.nb_tests += other.nb_tests; self.nb_errors += other.nb_errors; } } pub fn read_dirs, F: FnMut(&Path, &str)>(dirs: &[P], callback: &mut F) { for dir in dirs { read_dir(dir, callback); } } fn read_dir, F: FnMut(&Path, &str)>(dir: P, callback: &mut F) { for entry in fs::read_dir(dir).expect("read_dir failed") { let entry = entry.expect("entry failed"); let path = entry.path(); if path.is_dir() { read_dir(path, callback); } else { let content = read_file(&path); callback(&path, &content); } } } fn read_file>(p: P) -> String { let mut f = File::open(p).expect("read_file::open failed"); let mut content = String::with_capacity(f.metadata().map(|m| m.len() as usize + 1).unwrap_or(0)); f.read_to_string(&mut content) .expect("read_file::read_to_end failed"); content } pub fn show_error(p: &Path, err: &str) { eprintln!("=> [{}]: {err}", p.display()); }