2021-09-08 09:31:47 -05:00
|
|
|
#![warn(rust_2018_idioms, unused_lifetimes)]
|
2019-01-23 02:49:02 -06:00
|
|
|
#![allow(clippy::assertions_on_constants)]
|
2021-11-04 07:52:36 -05:00
|
|
|
#![feature(path_file_prefix)]
|
2019-01-23 02:49:02 -06:00
|
|
|
|
2021-11-04 07:52:36 -05:00
|
|
|
use std::cmp::Ordering;
|
|
|
|
use std::ffi::OsStr;
|
2019-01-17 22:19:51 -06:00
|
|
|
use std::fs::{self, DirEntry};
|
|
|
|
use std::path::Path;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_missing_tests() {
|
2019-01-17 22:50:30 -06:00
|
|
|
let missing_files = explore_directory(Path::new("./tests"));
|
2019-01-17 23:12:35 -06:00
|
|
|
if !missing_files.is_empty() {
|
2019-01-17 22:50:30 -06:00
|
|
|
assert!(
|
|
|
|
false,
|
2021-02-02 13:24:42 -06:00
|
|
|
"Didn't see a test file for the following files:\n\n{}\n",
|
|
|
|
missing_files
|
|
|
|
.iter()
|
2022-10-06 02:44:38 -05:00
|
|
|
.map(|s| format!("\t{s}"))
|
2021-02-02 13:24:42 -06:00
|
|
|
.collect::<Vec<_>>()
|
|
|
|
.join("\n")
|
2019-01-17 22:50:30 -06:00
|
|
|
);
|
|
|
|
}
|
2019-01-17 22:19:51 -06:00
|
|
|
}
|
|
|
|
|
2021-11-04 07:52:36 -05:00
|
|
|
// Test for missing files.
|
2019-01-17 22:50:30 -06:00
|
|
|
fn explore_directory(dir: &Path) -> Vec<String> {
|
|
|
|
let mut missing_files: Vec<String> = Vec::new();
|
2019-01-17 22:19:51 -06:00
|
|
|
let mut current_file = String::new();
|
2019-01-17 22:50:30 -06:00
|
|
|
let mut files: Vec<DirEntry> = fs::read_dir(dir).unwrap().filter_map(Result::ok).collect();
|
2021-11-04 07:52:36 -05:00
|
|
|
files.sort_by(|x, y| {
|
|
|
|
match x.path().file_prefix().cmp(&y.path().file_prefix()) {
|
|
|
|
Ordering::Equal => (),
|
|
|
|
ord => return ord,
|
|
|
|
}
|
|
|
|
// Sort rs files before the others if they share the same prefix. So when we see
|
|
|
|
// the file prefix for the first time and it's not a rust file, it means the rust
|
|
|
|
// file has to be missing.
|
|
|
|
match (
|
|
|
|
x.path().extension().and_then(OsStr::to_str),
|
|
|
|
y.path().extension().and_then(OsStr::to_str),
|
|
|
|
) {
|
2023-07-02 07:35:19 -05:00
|
|
|
(Some("rs" | "toml"), _) => Ordering::Less,
|
|
|
|
(_, Some("rs" | "toml")) => Ordering::Greater,
|
2021-11-04 07:52:36 -05:00
|
|
|
_ => Ordering::Equal,
|
|
|
|
}
|
|
|
|
});
|
2019-01-17 23:12:35 -06:00
|
|
|
for entry in &files {
|
2019-01-17 22:19:51 -06:00
|
|
|
let path = entry.path();
|
|
|
|
if path.is_dir() {
|
2019-01-17 22:50:30 -06:00
|
|
|
missing_files.extend(explore_directory(&path));
|
2019-01-17 22:19:51 -06:00
|
|
|
} else {
|
2021-11-04 07:52:36 -05:00
|
|
|
let file_prefix = path.file_prefix().unwrap().to_str().unwrap().to_string();
|
2019-01-17 23:12:35 -06:00
|
|
|
if let Some(ext) = path.extension() {
|
|
|
|
match ext.to_str().unwrap() {
|
2024-03-07 10:19:29 -06:00
|
|
|
"rs" | "toml" => current_file.clone_from(&file_prefix),
|
2019-01-17 23:12:35 -06:00
|
|
|
"stderr" | "stdout" => {
|
2021-11-04 07:52:36 -05:00
|
|
|
if file_prefix != current_file {
|
2019-01-17 23:12:35 -06:00
|
|
|
missing_files.push(path.to_str().unwrap().to_string());
|
|
|
|
}
|
|
|
|
},
|
|
|
|
_ => continue,
|
|
|
|
};
|
2019-01-17 22:19:51 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-17 22:50:30 -06:00
|
|
|
missing_files
|
2019-01-17 22:19:51 -06:00
|
|
|
}
|