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