Skip to content

Commit

Permalink
Auto merge of rust-lang#6471 - phansch:fix-bless, r=flip1995
Browse files Browse the repository at this point in the history
Fix blessing of new reference files

Adding of new reference files wasn't handled correctly. It was trying to
read a file that didn't exist yet.

Instead of unwrapping, we now treat a missing reference file as empty
(`Vec::new`). This makes the following conditional work. We then also
have to re-read the reference file after it was being copied. This
second read is technically the same as in the old shell script, but
wasn't really obvious there. The shell script did a `-s` test which
reads the file as well.

changelog: internal: Fix `cargo dev bless` when new reference files are added
  • Loading branch information
bors committed Dec 19, 2020
2 parents 0718eeb + dfb4ea5 commit 73feb31
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion clippy_dev/src/bless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,16 @@ fn update_reference_file(reference_file_path: PathBuf) {
}

let test_output_file = fs::read(&test_output_path).expect("Unable to read test output file");
let reference_file = fs::read(&reference_file_path).expect("Unable to read reference file");
let reference_file = fs::read(&reference_file_path).unwrap_or_default();

if test_output_file != reference_file {
// If a test run caused an output file to change, update the reference file
println!("updating {}", &relative_reference_file_path.display());
fs::copy(test_output_path, &reference_file_path).expect("Could not update reference file");

// We need to re-read the file now because it was potentially updated from copying
let reference_file = fs::read(&reference_file_path).unwrap_or_default();

if reference_file.is_empty() {
// If we copied over an empty output file, we remove the now empty reference file
println!("removing {}", &relative_reference_file_path.display());
Expand Down

0 comments on commit 73feb31

Please sign in to comment.