]> git.lizzy.rs Git - rust.git/blob - src/tools/tidy/src/ui_tests.rs
Increase tidy limit for parser by 1
[rust.git] / src / tools / tidy / src / ui_tests.rs
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
4
5 use std::fs;
6 use std::path::Path;
7
8 const ENTRY_LIMIT: usize = 1000;
9 // FIXME: The following limits should be reduced eventually.
10 const ROOT_ENTRY_LIMIT: usize = 1102;
11 const ISSUES_ENTRY_LIMIT: usize = 2310;
12 const PARSER_LIMIT: usize = 1005;
13
14 fn check_entries(path: &Path, bad: &mut bool) {
15     let dirs = walkdir::WalkDir::new(&path.join("test/ui"))
16         .into_iter()
17         .filter_entry(|e| e.file_type().is_dir());
18     for dir in dirs {
19         if let Ok(dir) = dir {
20             let dir_path = dir.path();
21
22             // Use special values for these dirs.
23             let is_root = path.join("test/ui") == dir_path;
24             let is_issues_dir = path.join("test/ui/issues") == dir_path;
25             let is_parser = path.join("test/ui/parser") == dir_path;
26             let limit = if is_root {
27                 ROOT_ENTRY_LIMIT
28             } else if is_issues_dir {
29                 ISSUES_ENTRY_LIMIT
30             } else if is_parser {
31                 PARSER_LIMIT
32             } else {
33                 ENTRY_LIMIT
34             };
35
36             let count = std::fs::read_dir(dir_path).unwrap().count();
37             if count > limit {
38                 tidy_error!(
39                     bad,
40                     "following path contains more than {} entries, \
41                     you should move the test to some relevant subdirectory (current: {}): {}",
42                     limit,
43                     count,
44                     dir_path.display()
45                 );
46             }
47         }
48     }
49 }
50
51 pub fn check(path: &Path, bad: &mut bool) {
52     check_entries(&path, bad);
53     for path in &[&path.join("test/ui"), &path.join("test/ui-fulldeps")] {
54         super::walk_no_read(path, &mut |_| false, &mut |entry| {
55             let file_path = entry.path();
56             if let Some(ext) = file_path.extension() {
57                 if ext == "stderr" || ext == "stdout" {
58                     // Test output filenames have one of the formats:
59                     // ```
60                     // $testname.stderr
61                     // $testname.$mode.stderr
62                     // $testname.$revision.stderr
63                     // $testname.$revision.$mode.stderr
64                     // ```
65                     //
66                     // For now, just make sure that there is a corresponding
67                     // `$testname.rs` file.
68                     //
69                     // NB: We do not use file_stem() as some file names have multiple `.`s and we
70                     // must strip all of them.
71                     let testname =
72                         file_path.file_name().unwrap().to_str().unwrap().split_once('.').unwrap().0;
73                     if !file_path.with_file_name(testname).with_extension("rs").exists() {
74                         tidy_error!(bad, "Stray file with UI testing output: {:?}", file_path);
75                     }
76
77                     if let Ok(metadata) = fs::metadata(file_path) {
78                         if metadata.len() == 0 {
79                             tidy_error!(bad, "Empty file with UI testing output: {:?}", file_path);
80                         }
81                     }
82                 }
83             }
84         });
85     }
86 }