File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ use std::fs::{self, DirEntry};
2+ use std::io;
3+ use std::path::Path;
4+
5+ #[test]
6+ fn test_missing_tests() {
7+ explore_directory(Path::new("./tests")).unwrap();
8+ }
9+
10+ /*
11+ Test for missing files.
12+
13+ Since rs files are alphabetically before stderr/stdout, we can sort by the full name
14+ and iter in that order. If we've seen the file stem for the first time and it's not
15+ a rust file, it means the rust file has to be missing.
16+ */
17+ fn explore_directory(dir: &Path) -> io::Result<()> {
18+ let mut current_file = String::new();
19+ let mut files: Vec<DirEntry> = fs::read_dir(dir)?.filter_map(Result::ok).collect();
20+ files.sort_by_key(|e| e.path());
21+ for entry in files.iter() {
22+ let path = entry.path();
23+ if path.is_dir() {
24+ explore_directory(&path)?;
25+ } else {
26+ let file_stem = path.file_stem().unwrap().to_str().unwrap().to_string();
27+ match path.extension() {
28+ Some(ext) => {
29+ match ext.to_str().unwrap() {
30+ "rs" => current_file = file_stem.clone(),
31+ "stderr" | "stdout" => {
32+ assert_eq!(
33+ file_stem,
34+ current_file,
35+ "{}",
36+ format!("Didn't see a test file for {:}", path.to_str().unwrap())
37+ );
38+ },
39+ _ => continue,
40+ };
41+ },
42+ None => {},
43+ }
44+ }
45+ }
46+ Ok(())
47+ }
You can’t perform that action at this time.
0 commit comments