Skip to content

Commit 5c10185

Browse files
committed
tidy: Add a check for empty UI test files
Check for empty `.stderr` and `.stdout` files in UI test directories. Empty files could still pass testing for `compile-pass` tests with no output so they can get into the repo accidentally, but they are not necessary and can be removed.
1 parent 0e325d0 commit 5c10185

File tree

1 file changed

+40
-23
lines changed

1 file changed

+40
-23
lines changed

src/tools/tidy/src/ui_tests.rs

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,49 @@
1010

1111
//! Tidy check to ensure that there are no stray `.stderr` files in UI test directories.
1212
13+
use std::fs;
1314
use std::path::Path;
1415

1516
pub fn check(path: &Path, bad: &mut bool) {
16-
super::walk_many(&[&path.join("test/ui"), &path.join("test/ui-fulldeps")],
17-
&mut |_| false,
18-
&mut |file_path| {
19-
if let Some(ext) = file_path.extension() {
20-
if ext == "stderr" || ext == "stdout" {
21-
// Test output filenames have the format:
22-
// $testname.stderr
23-
// $testname.$mode.stderr
24-
// $testname.$revision.stderr
25-
// $testname.$revision.$mode.stderr
26-
//
27-
// For now, just make sure that there is a corresponding
28-
// $testname.rs file.
29-
let testname = file_path.file_name().unwrap()
30-
.to_str().unwrap()
31-
.splitn(2, '.').next().unwrap();
32-
if !file_path.with_file_name(testname)
33-
.with_extension("rs")
34-
.exists() {
35-
println!("Stray file with UI testing output: {:?}", file_path);
36-
*bad = true;
17+
super::walk_many(
18+
&[&path.join("test/ui"), &path.join("test/ui-fulldeps")],
19+
&mut |_| false,
20+
&mut |file_path| {
21+
if let Some(ext) = file_path.extension() {
22+
if ext == "stderr" || ext == "stdout" {
23+
// Test output filenames have the format:
24+
// $testname.stderr
25+
// $testname.$mode.stderr
26+
// $testname.$revision.stderr
27+
// $testname.$revision.$mode.stderr
28+
//
29+
// For now, just make sure that there is a corresponding
30+
// $testname.rs file.
31+
let testname = file_path
32+
.file_name()
33+
.unwrap()
34+
.to_str()
35+
.unwrap()
36+
.splitn(2, '.')
37+
.next()
38+
.unwrap();
39+
if !file_path
40+
.with_file_name(testname)
41+
.with_extension("rs")
42+
.exists()
43+
{
44+
println!("Stray file with UI testing output: {:?}", file_path);
45+
*bad = true;
46+
}
47+
48+
if let Ok(metadata) = fs::metadata(file_path) {
49+
if metadata.len() == 0 {
50+
println!("Empty file with UI testing output: {:?}", file_path);
51+
*bad = true;
52+
}
53+
}
3754
}
3855
}
39-
}
40-
});
56+
},
57+
);
4158
}

0 commit comments

Comments
 (0)