Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/tools/run-make-support/src/diff/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct Diff {
actual: Option<String>,
actual_name: Option<String>,
normalizers: Vec<(String, String)>,
bless_dir: Option<String>,
drop_bomb: DropBomb,
}

Expand All @@ -37,13 +38,21 @@ impl Diff {
actual: None,
actual_name: None,
normalizers: Vec::new(),
bless_dir: std::env::var("RUSTC_BLESS_TEST").ok(),
drop_bomb: DropBomb::arm("diff"),
}
}

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

Expand Down Expand Up @@ -148,7 +157,7 @@ impl Diff {
let Some(ref expected_file) = self.expected_file else {
return false;
};
let Ok(bless_dir) = std::env::var("RUSTC_BLESS_TEST") else {
let Some(ref bless_dir) = self.bless_dir else {
return false;
};

Expand Down
Loading