Skip to content

Commit 6d91017

Browse files
committed
Extract a helper method for blessing in Diff
1 parent e9e27ab commit 6d91017

File tree

1 file changed

+19
-16
lines changed
  • src/tools/run-make-support/src/diff

1 file changed

+19
-16
lines changed

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

+19-16
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,8 @@ impl Diff {
112112
let (expected_name, actual_name, output, actual) = self.run_common();
113113

114114
if !output.is_empty() {
115-
// If we can bless (meaning we have a file to write into and the `RUSTC_BLESS_TEST`
116-
// environment variable set), then we write into the file and return.
117-
if let Some(ref expected_file) = self.expected_file {
118-
if std::env::var("RUSTC_BLESS_TEST").is_ok() {
119-
println!("Blessing `{}`", expected_file.display());
120-
fs::write(expected_file, actual);
121-
return;
122-
}
115+
if self.maybe_bless_expected_file(&actual) {
116+
return;
123117
}
124118
panic!(
125119
"test failed: `{}` is different from `{}`\n\n{}",
@@ -134,19 +128,28 @@ impl Diff {
134128
let (expected_name, actual_name, output, actual) = self.run_common();
135129

136130
if output.is_empty() {
137-
// If we can bless (meaning we have a file to write into and the `RUSTC_BLESS_TEST`
138-
// environment variable set), then we write into the file and return.
139-
if let Some(ref expected_file) = self.expected_file {
140-
if std::env::var("RUSTC_BLESS_TEST").is_ok() {
141-
println!("Blessing `{}`", expected_file.display());
142-
fs::write(expected_file, actual);
143-
return;
144-
}
131+
if self.maybe_bless_expected_file(&actual) {
132+
return;
145133
}
146134
panic!(
147135
"test failed: `{}` is not different from `{}`\n\n{}",
148136
expected_name, actual_name, output
149137
)
150138
}
151139
}
140+
141+
/// If we have an expected file to write into, and `RUSTC_BLESS_TEST` is
142+
/// set, then write the actual output into the file and return `true`.
143+
fn maybe_bless_expected_file(&self, actual: &str) -> bool {
144+
let Some(ref expected_file) = self.expected_file else {
145+
return false;
146+
};
147+
if std::env::var("RUSTC_BLESS_TEST").is_err() {
148+
return false;
149+
}
150+
151+
println!("Blessing `{}`", expected_file.display());
152+
fs::write(expected_file, actual);
153+
true
154+
}
152155
}

0 commit comments

Comments
 (0)