Skip to content

Commit c4942cf

Browse files
Allow to bless diff tests
1 parent 56e112a commit c4942cf

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

Lines changed: 13 additions & 1 deletion
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

@@ -16,6 +16,7 @@ pub fn diff() -> Diff {
1616
pub struct Diff {
1717
expected: Option<String>,
1818
expected_name: Option<String>,
19+
expected_file: Option<PathBuf>,
1920
actual: Option<String>,
2021
actual_name: Option<String>,
2122
normalizers: Vec<(String, String)>,
@@ -29,6 +30,7 @@ impl Diff {
2930
Self {
3031
expected: None,
3132
expected_name: None,
33+
expected_file: None,
3234
actual: None,
3335
actual_name: None,
3436
normalizers: Vec::new(),
@@ -42,6 +44,7 @@ impl Diff {
4244
let content = std::fs::read_to_string(path).expect("failed to read file");
4345
let name = path.to_string_lossy().to_string();
4446

47+
self.expected_file = Some(path.into());
4548
self.expected = Some(content);
4649
self.expected_name = Some(name);
4750
self
@@ -103,6 +106,15 @@ impl Diff {
103106
.to_string();
104107

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

0 commit comments

Comments
 (0)