Skip to content

Commit a3b3a54

Browse files
author
Unknown
committed
Update to collect all the files then throw the error.
1 parent 8b81208 commit a3b3a54

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

tests/missing-test-files.rs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
use std::fs::{self, DirEntry};
2-
use std::io;
32
use std::path::Path;
43

54
#[test]
65
fn test_missing_tests() {
7-
explore_directory(Path::new("./tests")).unwrap();
6+
let missing_files = explore_directory(Path::new("./tests"));
7+
if missing_files.len() > 0 {
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+
}
820
}
921

1022
/*
@@ -14,27 +26,25 @@ Since rs files are alphabetically before stderr/stdout, we can sort by the full
1426
and iter in that order. If we've seen the file stem for the first time and it's not
1527
a rust file, it means the rust file has to be missing.
1628
*/
17-
fn explore_directory(dir: &Path) -> io::Result<()> {
29+
fn explore_directory(dir: &Path) -> Vec<String> {
30+
let mut missing_files: Vec<String> = Vec::new();
1831
let mut current_file = String::new();
19-
let mut files: Vec<DirEntry> = fs::read_dir(dir)?.filter_map(Result::ok).collect();
32+
let mut files: Vec<DirEntry> = fs::read_dir(dir).unwrap().filter_map(Result::ok).collect();
2033
files.sort_by_key(|e| e.path());
2134
for entry in files.iter() {
2235
let path = entry.path();
2336
if path.is_dir() {
24-
explore_directory(&path)?;
37+
missing_files.extend(explore_directory(&path));
2538
} else {
2639
let file_stem = path.file_stem().unwrap().to_str().unwrap().to_string();
2740
match path.extension() {
2841
Some(ext) => {
2942
match ext.to_str().unwrap() {
3043
"rs" => current_file = file_stem.clone(),
3144
"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-
);
45+
if file_stem != current_file {
46+
missing_files.push(path.to_str().unwrap().to_string());
47+
}
3848
},
3949
_ => continue,
4050
};
@@ -43,5 +53,5 @@ fn explore_directory(dir: &Path) -> io::Result<()> {
4353
}
4454
}
4555
}
46-
Ok(())
56+
missing_files
4757
}

0 commit comments

Comments
 (0)