(options: &Options)
| 23 | } |
| 24 | |
| 25 | pub fn run(options: &Options) -> Result<()> { |
| 26 | let stdin_exist = options |
| 27 | .files |
| 28 | .iter() |
| 29 | .find(|file| *file == Path::new("-")) |
| 30 | .is_some(); |
| 31 | let filtered_files = options |
| 32 | .files |
| 33 | .iter() |
| 34 | .cloned() |
| 35 | .filter(|file| *file != Path::new("-")) |
| 36 | .collect::<Vec<_>>(); |
| 37 | let mut total = 0; |
| 38 | let mut errors = 0; |
| 39 | let mut special_files: Vec<PathBuf> = vec![]; |
| 40 | if stdin_exist { |
| 41 | special_files.push("-".into()); |
| 42 | } |
| 43 | for file in iterate_files(&filtered_files).chain(special_files) { |
| 44 | total += 1; |
| 45 | match run_single_file(&file) { |
| 46 | Ok(_) => { |
| 47 | if options.verbose { |
| 48 | println!("{}", file.to_string_lossy()); |
| 49 | } |
| 50 | } |
| 51 | Err(e) => { |
| 52 | if options.verbose { |
| 53 | println!("{}: {}", file.to_string_lossy(), e); |
| 54 | } |
| 55 | errors += 1; |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | if options.verbose { |
| 61 | match total { |
| 62 | 0 => println!("0 files"), |
| 63 | 1 => println!("1 file"), |
| 64 | n => println!("{n} files"), |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | match errors { |
| 69 | 0 => Ok(()), |
| 70 | 1 => anyhow::bail!("1 failure"), |
| 71 | n => anyhow::bail!("{n} failures"), |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | /// Run all functions in a file that are succeeded by "run:" comments |
| 76 | fn run_single_file(path: &PathBuf) -> Result<()> { |
nothing calls this directly
no test coverage detected