about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-01-20 23:37:41 +0100
committerGitHub <noreply@github.com>2022-01-20 23:37:41 +0100
commit5e46f7dceb86b3dabd566750f7903d00f601a9c6 (patch)
tree58526d07a098587aa2c2e272749bcd429c7437e2
parentd4ec46444b8e0fc5f4deaf4408cd0cab367178f1 (diff)
parentdcb0721a29f63cd2fb3a30487c81cfb657f0a7ee (diff)
downloadrust-5e46f7dceb86b3dabd566750f7903d00f601a9c6.tar.gz
rust-5e46f7dceb86b3dabd566750f7903d00f601a9c6.zip
Rollup merge of #93104 - dtolnay:ppbless, r=Mark-Simulacrum
Support --bless for pp-exact pretty printer tests

I ran into this while working on the stack of PRs containing #93102. `x.py test src/test/pretty --bless` previously would `fatal` instead of blessing the input files.

Tested by making a silly pretty-printer tweak and running the above command: 98823c3929ebfe796786345c5ee713f63317d9c6
-rw-r--r--src/tools/compiletest/src/runtest.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs
index f039ba59d23..22785013085 100644
--- a/src/tools/compiletest/src/runtest.rs
+++ b/src/tools/compiletest/src/runtest.rs
@@ -500,7 +500,19 @@ impl<'test> TestCx<'test> {
             expected = expected.replace(&cr, "");
         }
 
-        self.compare_source(&expected, &actual);
+        if !self.config.bless {
+            self.compare_source(&expected, &actual);
+        } else if expected != actual {
+            let filepath_buf;
+            let filepath = match &self.props.pp_exact {
+                Some(file) => {
+                    filepath_buf = self.testpaths.file.parent().unwrap().join(file);
+                    &filepath_buf
+                }
+                None => &self.testpaths.file,
+            };
+            fs::write(filepath, &actual).unwrap();
+        }
 
         // If we're only making sure that the output matches then just stop here
         if self.props.pretty_compare_only {