Account for revisions in missing-test-files

This commit is contained in:
Gary Guo 2021-10-24 22:19:59 +01:00
parent 7e5f99ab58
commit 14e0390fdf

View File

@ -1,7 +1,10 @@
#![cfg_attr(feature = "deny-warnings", deny(warnings))] #![cfg_attr(feature = "deny-warnings", deny(warnings))]
#![warn(rust_2018_idioms, unused_lifetimes)] #![warn(rust_2018_idioms, unused_lifetimes)]
#![allow(clippy::assertions_on_constants)] #![allow(clippy::assertions_on_constants)]
#![feature(path_file_prefix)]
use std::cmp::Ordering;
use std::ffi::OsStr;
use std::fs::{self, DirEntry}; use std::fs::{self, DirEntry};
use std::path::Path; use std::path::Path;
@ -21,29 +24,39 @@ fn test_missing_tests() {
} }
} }
/* // Test for missing files.
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) -> Vec<String> { fn explore_directory(dir: &Path) -> Vec<String> {
let mut missing_files: Vec<String> = Vec::new(); let mut missing_files: Vec<String> = Vec::new();
let mut current_file = String::new(); let mut current_file = String::new();
let mut files: Vec<DirEntry> = fs::read_dir(dir).unwrap().filter_map(Result::ok).collect(); let mut files: Vec<DirEntry> = fs::read_dir(dir).unwrap().filter_map(Result::ok).collect();
files.sort_by_key(std::fs::DirEntry::path); 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),
) {
(Some("rs"), _) => Ordering::Less,
(_, Some("rs")) => Ordering::Greater,
_ => Ordering::Equal,
}
});
for entry in &files { for entry in &files {
let path = entry.path(); let path = entry.path();
if path.is_dir() { if path.is_dir() {
missing_files.extend(explore_directory(&path)); missing_files.extend(explore_directory(&path));
} else { } else {
let file_stem = path.file_stem().unwrap().to_str().unwrap().to_string(); let file_prefix = path.file_prefix().unwrap().to_str().unwrap().to_string();
if let Some(ext) = path.extension() { if let Some(ext) = path.extension() {
match ext.to_str().unwrap() { match ext.to_str().unwrap() {
"rs" => current_file = file_stem.clone(), "rs" => current_file = file_prefix.clone(),
"stderr" | "stdout" => { "stderr" | "stdout" => {
if file_stem != current_file { if file_prefix != current_file {
missing_files.push(path.to_str().unwrap().to_string()); missing_files.push(path.to_str().unwrap().to_string());
} }
}, },