1 #![allow(clippy::assertions_on_constants)]
3 use std::fs::{self, DirEntry};
7 fn test_missing_tests() {
8 let missing_files = explore_directory(Path::new("./tests"));
9 if !missing_files.is_empty() {
12 "Didn't see a test file for the following files:\n\n{}\n",
15 .map(|s| format!("\t{}", s))
23 Test for missing files.
25 Since rs files are alphabetically before stderr/stdout, we can sort by the full name
26 and iter in that order. If we've seen the file stem for the first time and it's not
27 a rust file, it means the rust file has to be missing.
29 fn explore_directory(dir: &Path) -> Vec<String> {
30 let mut missing_files: Vec<String> = Vec::new();
31 let mut current_file = String::new();
32 let mut files: Vec<DirEntry> = fs::read_dir(dir).unwrap().filter_map(Result::ok).collect();
33 files.sort_by_key(std::fs::DirEntry::path);
35 let path = entry.path();
37 missing_files.extend(explore_directory(&path));
39 let file_stem = path.file_stem().unwrap().to_str().unwrap().to_string();
40 if let Some(ext) = path.extension() {
41 match ext.to_str().unwrap() {
42 "rs" => current_file = file_stem.clone(),
43 "stderr" | "stdout" => {
44 if file_stem != current_file {
45 missing_files.push(path.to_str().unwrap().to_string());