1 #![cfg_attr(feature = "deny-warnings", deny(warnings))]
2 #![warn(rust_2018_idioms, unused_lifetimes)]
3 #![allow(clippy::assertions_on_constants)]
4 #![feature(path_file_prefix)]
6 use std::cmp::Ordering;
8 use std::fs::{self, DirEntry};
12 fn test_missing_tests() {
13 let missing_files = explore_directory(Path::new("./tests"));
14 if !missing_files.is_empty() {
17 "Didn't see a test file for the following files:\n\n{}\n",
20 .map(|s| format!("\t{s}"))
27 // Test for missing files.
28 fn explore_directory(dir: &Path) -> Vec<String> {
29 let mut missing_files: Vec<String> = Vec::new();
30 let mut current_file = String::new();
31 let mut files: Vec<DirEntry> = fs::read_dir(dir).unwrap().filter_map(Result::ok).collect();
32 files.sort_by(|x, y| {
33 match x.path().file_prefix().cmp(&y.path().file_prefix()) {
34 Ordering::Equal => (),
37 // Sort rs files before the others if they share the same prefix. So when we see
38 // the file prefix for the first time and it's not a rust file, it means the rust
39 // file has to be missing.
41 x.path().extension().and_then(OsStr::to_str),
42 y.path().extension().and_then(OsStr::to_str),
44 (Some("rs"), _) => Ordering::Less,
45 (_, Some("rs")) => Ordering::Greater,
50 let path = entry.path();
52 missing_files.extend(explore_directory(&path));
54 let file_prefix = path.file_prefix().unwrap().to_str().unwrap().to_string();
55 if let Some(ext) = path.extension() {
56 match ext.to_str().unwrap() {
57 "rs" => current_file = file_prefix.clone(),
58 "stderr" | "stdout" => {
59 if file_prefix != current_file {
60 missing_files.push(path.to_str().unwrap().to_string());