about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--tests/missing-test-files.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/missing-test-files.rs b/tests/missing-test-files.rs
new file mode 100644
index 00000000000..31d2dccff71
--- /dev/null
+++ b/tests/missing-test-files.rs
@@ -0,0 +1,47 @@
+use std::fs::{self, DirEntry};
+use std::io;
+use std::path::Path;
+
+#[test]
+fn test_missing_tests() {
+    explore_directory(Path::new("./tests")).unwrap();
+}
+
+/*
+Test for missing files.
+
+Since rs files are alphabetically before stderr/stdout, we can sort by the full name
+and iter in that order. If we've seen the file stem for the first time and it's not
+a rust file, it means the rust file has to be missing.
+*/
+fn explore_directory(dir: &Path) -> io::Result<()> {
+    let mut current_file = String::new();
+    let mut files: Vec<DirEntry> = fs::read_dir(dir)?.filter_map(Result::ok).collect();
+    files.sort_by_key(|e| e.path());
+    for entry in files.iter() {
+        let path = entry.path();
+        if path.is_dir() {
+            explore_directory(&path)?;
+        } else {
+            let file_stem = path.file_stem().unwrap().to_str().unwrap().to_string();
+            match path.extension() {
+                Some(ext) => {
+                    match ext.to_str().unwrap() {
+                        "rs" => current_file = file_stem.clone(),
+                        "stderr" | "stdout" => {
+                            assert_eq!(
+                                file_stem,
+                                current_file,
+                                "{}",
+                                format!("Didn't see a test file for {:}", path.to_str().unwrap())
+                            );
+                        },
+                        _ => continue,
+                    };
+                },
+                None => {},
+            }
+        }
+    }
+    Ok(())
+}