about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-11-05 00:02:05 +0100
committerGitHub <noreply@github.com>2022-11-05 00:02:05 +0100
commitb1a47d2fd95e64227c07b428ba2e5170fac368f8 (patch)
treedacc45b199cf97a0bd8795576d89d0b2e23fc031 /src
parent7b518af5d92e1f5aa4ff9946cc1fa17bd4fa9cdd (diff)
parentd98cce19b28f37a457db3d27ff5ade33f32bcaa4 (diff)
downloadrust-b1a47d2fd95e64227c07b428ba2e5170fac368f8.tar.gz
rust-b1a47d2fd95e64227c07b428ba2e5170fac368f8.zip
Rollup merge of #103956 - JakobDegen:tidy-bless, r=jyn514
Make mir opt unused file check blessable

Makes it slightly nicer to work with.

Can't write automated test but tested locally via

```
$ touch src/test/mir-opt/random
$ x test tidy // shows failure
$ x test tidy --bless // file gone
```

r? `@jyn514`
Diffstat (limited to 'src')
-rw-r--r--src/tools/tidy/src/mir_opt_tests.rs18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/tools/tidy/src/mir_opt_tests.rs b/src/tools/tidy/src/mir_opt_tests.rs
index ea24fa45138..018573284ea 100644
--- a/src/tools/tidy/src/mir_opt_tests.rs
+++ b/src/tools/tidy/src/mir_opt_tests.rs
@@ -3,7 +3,7 @@
 use std::collections::HashSet;
 use std::path::{Path, PathBuf};
 
-fn check_unused_files(path: &Path, bad: &mut bool) {
+fn check_unused_files(path: &Path, bless: bool, bad: &mut bool) {
     let mut rs_files = Vec::<PathBuf>::new();
     let mut output_files = HashSet::<PathBuf>::new();
     let files = walkdir::WalkDir::new(&path.join("test/mir-opt")).into_iter();
@@ -27,11 +27,15 @@ fn check_unused_files(path: &Path, bad: &mut bool) {
 
     for extra in output_files {
         if extra.file_name() != Some("README.md".as_ref()) {
-            tidy_error!(
-                bad,
-                "the following output file is not associated with any mir-opt test, you can remove it: {}",
-                extra.display()
-            );
+            if !bless {
+                tidy_error!(
+                    bad,
+                    "the following output file is not associated with any mir-opt test, you can remove it: {}",
+                    extra.display()
+                );
+            } else {
+                let _ = std::fs::remove_file(extra);
+            }
         }
     }
 }
@@ -65,6 +69,6 @@ fn check_dash_files(path: &Path, bless: bool, bad: &mut bool) {
 }
 
 pub fn check(path: &Path, bless: bool, bad: &mut bool) {
-    check_unused_files(path, bad);
+    check_unused_files(path, bless, bad);
     check_dash_files(path, bless, bad);
 }