about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJane Lusby <jlusby42@gmail.com>2018-05-15 19:15:43 -0700
committerJane Lusby <jlusby42@gmail.com>2018-05-16 10:19:45 -0700
commit5c10185aeedd45af551ec3e49304f9e94226c21a (patch)
tree69750a05d494cec4a1970f7c17fb774cb9168c1c
parent0e325d0141ce8d86524f55c2df53835aab895096 (diff)
downloadrust-5c10185aeedd45af551ec3e49304f9e94226c21a.tar.gz
rust-5c10185aeedd45af551ec3e49304f9e94226c21a.zip
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.
-rw-r--r--src/tools/tidy/src/ui_tests.rs63
1 files changed, 40 insertions, 23 deletions
diff --git a/src/tools/tidy/src/ui_tests.rs b/src/tools/tidy/src/ui_tests.rs
index 351005ff4b8..c1574407807 100644
--- a/src/tools/tidy/src/ui_tests.rs
+++ b/src/tools/tidy/src/ui_tests.rs
@@ -10,32 +10,49 @@
 
 //! Tidy check to ensure that there are no stray `.stderr` files in UI test directories.
 
+use std::fs;
 use std::path::Path;
 
 pub fn check(path: &Path, bad: &mut bool) {
-    super::walk_many(&[&path.join("test/ui"), &path.join("test/ui-fulldeps")],
-                     &mut |_| false,
-                     &mut |file_path| {
-        if let Some(ext) = file_path.extension() {
-            if ext == "stderr" || ext == "stdout" {
-                // Test output filenames have the format:
-                // $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.
-                let testname = file_path.file_name().unwrap()
-                                        .to_str().unwrap()
-                                        .splitn(2, '.').next().unwrap();
-                if !file_path.with_file_name(testname)
-                             .with_extension("rs")
-                             .exists() {
-                    println!("Stray file with UI testing output: {:?}", file_path);
-                    *bad = true;
+    super::walk_many(
+        &[&path.join("test/ui"), &path.join("test/ui-fulldeps")],
+        &mut |_| false,
+        &mut |file_path| {
+            if let Some(ext) = file_path.extension() {
+                if ext == "stderr" || ext == "stdout" {
+                    // Test output filenames have the format:
+                    // $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.
+                    let testname = file_path
+                        .file_name()
+                        .unwrap()
+                        .to_str()
+                        .unwrap()
+                        .splitn(2, '.')
+                        .next()
+                        .unwrap();
+                    if !file_path
+                        .with_file_name(testname)
+                        .with_extension("rs")
+                        .exists()
+                    {
+                        println!("Stray file with UI testing output: {:?}", file_path);
+                        *bad = true;
+                    }
+
+                    if let Ok(metadata) = fs::metadata(file_path) {
+                        if metadata.len() == 0 {
+                            println!("Empty file with UI testing output: {:?}", file_path);
+                            *bad = true;
+                        }
+                    }
                 }
             }
-        }
-    });
+        },
+    );
 }