1 //! Tidy check to ensure below in UI test directories:
2 //! - the number of entries in each directory must be less than `ENTRY_LIMIT`
3 //! - there are no stray `.stderr` files
6 use ignore::WalkBuilder;
10 const ENTRY_LIMIT: usize = 1000;
11 // FIXME: The following limits should be reduced eventually.
12 const ROOT_ENTRY_LIMIT: usize = 939;
13 const ISSUES_ENTRY_LIMIT: usize = 2050;
15 fn check_entries(path: &Path, bad: &mut bool) {
16 for dir in Walk::new(&path.join("test/ui")) {
17 if let Ok(entry) = dir {
18 if entry.file_type().map(|ft| ft.is_dir()).unwrap_or(false) {
19 let dir_path = entry.path();
20 // Use special values for these dirs.
21 let is_root = path.join("test/ui") == dir_path;
22 let is_issues_dir = path.join("test/ui/issues") == dir_path;
23 let limit = if is_root {
25 } else if is_issues_dir {
31 let count = WalkBuilder::new(&dir_path)
37 - 1; // remove the dir itself
42 "following path contains more than {} entries, \
43 you should move the test to some relevant subdirectory (current: {}): {}",
54 pub fn check(path: &Path, bad: &mut bool) {
55 check_entries(&path, bad);
56 for path in &[&path.join("test/ui"), &path.join("test/ui-fulldeps")] {
57 crate::walk::walk_no_read(path, &mut |_| false, &mut |entry| {
58 let file_path = entry.path();
59 if let Some(ext) = file_path.extension() {
60 if ext == "stderr" || ext == "stdout" {
61 // Test output filenames have one of the formats:
64 // $testname.$mode.stderr
65 // $testname.$revision.stderr
66 // $testname.$revision.$mode.stderr
69 // For now, just make sure that there is a corresponding
70 // `$testname.rs` file.
72 // NB: We do not use file_stem() as some file names have multiple `.`s and we
73 // must strip all of them.
75 file_path.file_name().unwrap().to_str().unwrap().split_once('.').unwrap().0;
76 if !file_path.with_file_name(testname).with_extension("rs").exists() {
77 tidy_error!(bad, "Stray file with UI testing output: {:?}", file_path);
80 if let Ok(metadata) = fs::metadata(file_path) {
81 if metadata.len() == 0 {
82 tidy_error!(bad, "Empty file with UI testing output: {:?}", file_path);