Skip to content

Commit a88e29b

Browse files
authored
Rollup merge of #144954 - Zalathar:run-make-bless, r=jieyouxu
run-make: Allow blessing snapshot files that don't exist yet This makes it possible to bless the snapshot files used by `diff()` in newly-created run-make tests, without having to create the files manually beforehand. r? jieyouxu
2 parents 07e8634 + f96fbb2 commit a88e29b

File tree

1 file changed

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

1 file changed

+10
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub struct Diff {
2323
actual: Option<String>,
2424
actual_name: Option<String>,
2525
normalizers: Vec<(String, String)>,
26+
bless_dir: Option<String>,
2627
drop_bomb: DropBomb,
2728
}
2829

@@ -37,13 +38,21 @@ impl Diff {
3738
actual: None,
3839
actual_name: None,
3940
normalizers: Vec::new(),
41+
bless_dir: std::env::var("RUSTC_BLESS_TEST").ok(),
4042
drop_bomb: DropBomb::arm("diff"),
4143
}
4244
}
4345

4446
/// Specify the expected output for the diff from a file.
4547
pub fn expected_file<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
4648
let path = path.as_ref();
49+
// In `--bless` mode, create the snapshot file if it doesn't already exist.
50+
// The empty file will be overwritten with the actual text.
51+
if self.bless_dir.is_some()
52+
&& let Ok(false) = std::fs::exists(path)
53+
{
54+
fs::write(path, "");
55+
}
4756
let content = fs::read_to_string(path);
4857
let name = path.to_string_lossy().to_string();
4958

@@ -148,7 +157,7 @@ impl Diff {
148157
let Some(ref expected_file) = self.expected_file else {
149158
return false;
150159
};
151-
let Ok(bless_dir) = std::env::var("RUSTC_BLESS_TEST") else {
160+
let Some(ref bless_dir) = self.bless_dir else {
152161
return false;
153162
};
154163

0 commit comments

Comments
 (0)