Skip to content

Commit 9bff230

Browse files
Allow to bless diff tests
1 parent 921645c commit 9bff230

File tree

1 file changed

+13
-1
lines changed
  • src/tools/run-make-support/src/diff

1 file changed

+13
-1
lines changed

src/tools/run-make-support/src/diff/mod.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use regex::Regex;
22
use similar::TextDiff;
3-
use std::path::Path;
3+
use std::path::{Path, PathBuf};
44

55
use crate::drop_bomb::DropBomb;
66

@@ -17,6 +17,7 @@ pub fn diff() -> Diff {
1717
pub struct Diff {
1818
expected: Option<String>,
1919
expected_name: Option<String>,
20+
expected_file: Option<PathBuf>,
2021
actual: Option<String>,
2122
actual_name: Option<String>,
2223
normalizers: Vec<(String, String)>,
@@ -30,6 +31,7 @@ impl Diff {
3031
Self {
3132
expected: None,
3233
expected_name: None,
34+
expected_file: None,
3335
actual: None,
3436
actual_name: None,
3537
normalizers: Vec::new(),
@@ -43,6 +45,7 @@ impl Diff {
4345
let content = std::fs::read_to_string(path).expect("failed to read file");
4446
let name = path.to_string_lossy().to_string();
4547

48+
self.expected_file = Some(path.into());
4649
self.expected = Some(content);
4750
self.expected_name = Some(name);
4851
self
@@ -104,6 +107,15 @@ impl Diff {
104107
.to_string();
105108

106109
if !output.is_empty() {
110+
// If we can bless (meaning we have a file to write into and the `RUSTC_BLESS_TEST`
111+
// environment variable set), then we write into the file and return.
112+
if let Some(ref expected_file) = self.expected_file {
113+
if std::env::var("RUSTC_BLESS_TEST").is_ok() {
114+
println!("Blessing `{}`", expected_file.display());
115+
std::fs::write(expected_file, actual).unwrap();
116+
return;
117+
}
118+
}
107119
panic!(
108120
"test failed: `{}` is different from `{}`\n\n{}",
109121
expected_name, actual_name, output

0 commit comments

Comments
 (0)