diff options
| author | bors <bors@rust-lang.org> | 2019-01-18 08:27:06 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-01-18 08:27:06 +0000 |
| commit | 235f96005cb3c94f4f3d185e7c3d4ffaa08685aa (patch) | |
| tree | 362b52fa089ba91fb8c3c9f2ab4c794ebe6a3028 | |
| parent | f48e605ec4cb68870ee0138a463fa77323d2cd6f (diff) | |
| parent | 38b3a4ec6309429a6ea4acced6dc2d5e1d745622 (diff) | |
| download | rust-235f96005cb3c94f4f3d185e7c3d4ffaa08685aa.tar.gz rust-235f96005cb3c94f4f3d185e7c3d4ffaa08685aa.zip | |
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.
| -rw-r--r-- | tests/missing-test-files.rs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/missing-test-files.rs b/tests/missing-test-files.rs new file mode 100644 index 00000000000..558e001d3d1 --- /dev/null +++ b/tests/missing-test-files.rs @@ -0,0 +1,54 @@ +use std::fs::{self, DirEntry}; +use std::path::Path; + +#[test] +fn test_missing_tests() { + let missing_files = explore_directory(Path::new("./tests")); + if !missing_files.is_empty() { + assert!( + false, + format!( + "Didn't see a test file for the following files:\n\n{}\n", + missing_files + .iter() + .map(|s| format!("\t{}", s)) + .collect::<Vec<_>>() + .join("\n") + ) + ); + } +} + +/* +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> { + let mut missing_files: Vec<String> = Vec::new(); + let mut current_file = String::new(); + let mut files: Vec<DirEntry> = fs::read_dir(dir).unwrap().filter_map(Result::ok).collect(); + files.sort_by_key(|e| e.path()); + for entry in &files { + let path = entry.path(); + if path.is_dir() { + missing_files.extend(explore_directory(&path)); + } else { + let file_stem = path.file_stem().unwrap().to_str().unwrap().to_string(); + if let Some(ext) = path.extension() { + match ext.to_str().unwrap() { + "rs" => current_file = file_stem.clone(), + "stderr" | "stdout" => { + if file_stem != current_file { + missing_files.push(path.to_str().unwrap().to_string()); + } + }, + _ => continue, + }; + } + } + } + missing_files +} |
