Skip to content

Commit 235f960

Browse files
committed
Auto merge of #3669 - avborhanian:extra_results_files, r=oli-obk
Check for results files missing tests Addresses #3572. Basically iterates over all the files, and if it sees any files that don't have a matching rs file, it throws an error.
2 parents f48e605 + 38b3a4e commit 235f960

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

Diff for: tests/missing-test-files.rs

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
use std::fs::{self, DirEntry};
2+
use std::path::Path;
3+
4+
#[test]
5+
fn test_missing_tests() {
6+
let missing_files = explore_directory(Path::new("./tests"));
7+
if !missing_files.is_empty() {
8+
assert!(
9+
false,
10+
format!(
11+
"Didn't see a test file for the following files:\n\n{}\n",
12+
missing_files
13+
.iter()
14+
.map(|s| format!("\t{}", s))
15+
.collect::<Vec<_>>()
16+
.join("\n")
17+
)
18+
);
19+
}
20+
}
21+
22+
/*
23+
Test for missing files.
24+
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.
28+
*/
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(|e| e.path());
34+
for entry in &files {
35+
let path = entry.path();
36+
if path.is_dir() {
37+
missing_files.extend(explore_directory(&path));
38+
} else {
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());
46+
}
47+
},
48+
_ => continue,
49+
};
50+
}
51+
}
52+
}
53+
missing_files
54+
}

0 commit comments

Comments
 (0)