diff options
| author | Jieyou Xu <jieyouxu@outlook.com> | 2025-08-02 15:58:53 +0800 |
|---|---|---|
| committer | Jieyou Xu <jieyouxu@outlook.com> | 2025-08-02 16:17:40 +0800 |
| commit | c10dc999f004aa04d29652f6fa9dc9535cb10899 (patch) | |
| tree | 00575618583dbb3e68913f989155eb043f006ef9 | |
| parent | 5b03d0711ad6a2af1199fd28488a5c3ed813b130 (diff) | |
| download | rust-c10dc999f004aa04d29652f6fa9dc9535cb10899.tar.gz rust-c10dc999f004aa04d29652f6fa9dc9535cb10899.zip | |
Pull out stray/empty output snapshot checks into own functions
| -rw-r--r-- | src/tools/tidy/src/ui_tests.rs | 51 |
1 files changed, 29 insertions, 22 deletions
diff --git a/src/tools/tidy/src/ui_tests.rs b/src/tools/tidy/src/ui_tests.rs index 91b89d41149..ee26e81c97f 100644 --- a/src/tools/tidy/src/ui_tests.rs +++ b/src/tools/tidy/src/ui_tests.rs @@ -54,28 +54,8 @@ pub fn check(root_path: &Path, bless: bool, bad: &mut bool) { let testname = file_path.file_name().unwrap().to_str().unwrap().split_once('.').unwrap().0; if ext == "stderr" || ext == "stdout" || ext == "fixed" { - // Test output filenames have one of the formats: - // ``` - // $testname.stderr - // $testname.$mode.stderr - // $testname.$revision.stderr - // $testname.$revision.$mode.stderr - // ``` - // - // For now, just make sure that there is a corresponding - // `$testname.rs` file. - - if !file_path.with_file_name(testname).with_extension("rs").exists() - && !testname.contains("ignore-tidy") - { - tidy_error!(bad, "Stray file with UI testing output: {:?}", file_path); - } - - if let Ok(metadata) = fs::metadata(file_path) - && metadata.len() == 0 - { - tidy_error!(bad, "Empty file with UI testing output: {:?}", file_path); - } + check_stray_output_snapshot(bad, file_path, testname); + check_empty_output_snapshot(bad, file_path); } if ext == "rs" @@ -175,3 +155,30 @@ fn check_unexpected_extension(bad: &mut bool, file_path: &Path, ext: &str) { tidy_error!(bad, "file {} has unexpected extension {}", file_path.display(), ext); } } + +fn check_stray_output_snapshot(bad: &mut bool, file_path: &Path, testname: &str) { + // Test output filenames have one of the formats: + // ``` + // $testname.stderr + // $testname.$mode.stderr + // $testname.$revision.stderr + // $testname.$revision.$mode.stderr + // ``` + // + // For now, just make sure that there is a corresponding + // `$testname.rs` file. + + if !file_path.with_file_name(testname).with_extension("rs").exists() + && !testname.contains("ignore-tidy") + { + tidy_error!(bad, "Stray file with UI testing output: {:?}", file_path); + } +} + +fn check_empty_output_snapshot(bad: &mut bool, file_path: &Path) { + if let Ok(metadata) = fs::metadata(file_path) + && metadata.len() == 0 + { + tidy_error!(bad, "Empty file with UI testing output: {:?}", file_path); + } +} |
