]> git.lizzy.rs Git - rust.git/commitdiff
Support --bless for pp-exact pretty printer tests
authorDavid Tolnay <dtolnay@gmail.com>
Thu, 20 Jan 2022 04:12:31 +0000 (20:12 -0800)
committerDavid Tolnay <dtolnay@gmail.com>
Thu, 20 Jan 2022 04:15:08 +0000 (20:15 -0800)
src/tools/compiletest/src/runtest.rs

index f039ba59d231cdba12fd6d6fd1d344ad29e00aad..2278501308539f3433c068e71e5d331eb7c90c4f 100644 (file)
@@ -500,7 +500,19 @@ fn run_pretty_test(&self) {
             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 {