Skip to content

Commit 73feb31

Browse files
committed
Auto merge of #6471 - phansch:fix-bless, r=flip1995
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
2 parents 0718eeb + dfb4ea5 commit 73feb31

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

clippy_dev/src/bless.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,16 @@ fn update_reference_file(reference_file_path: PathBuf) {
4646
}
4747

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

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

56+
// We need to re-read the file now because it was potentially updated from copying
57+
let reference_file = fs::read(&reference_file_path).unwrap_or_default();
58+
5659
if reference_file.is_empty() {
5760
// If we copied over an empty output file, we remove the now empty reference file
5861
println!("removing {}", &relative_reference_file_path.display());

0 commit comments

Comments
 (0)