From 0f972650a54195058fcd4eee424890887d15270a Mon Sep 17 00:00:00 2001 From: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> Date: Fri, 22 Nov 2024 15:00:37 +0000 Subject: [PATCH] Add a test blessing mechanism --- masonry/src/testing/harness.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/masonry/src/testing/harness.rs b/masonry/src/testing/harness.rs index 71094052e..938df768e 100644 --- a/masonry/src/testing/harness.rs +++ b/masonry/src/testing/harness.rs @@ -666,16 +666,19 @@ impl TestHarness { // TODO: If this file is corrupted, it could be an lfs bandwidth/installation issue. // Have a warning for that case (i.e. differentiation between not-found and invalid format) // and a environment variable to ignore the test in that case. - if let Ok(reference_file) = ImageReader::open(reference_path) { + if let Ok(reference_file) = ImageReader::open(&reference_path) { let ref_image = reference_file.decode().unwrap().to_rgb8(); if let Some(diff_image) = get_image_diff(&ref_image, &new_image.to_rgb8()) { - // Remove '.new.png' '.diff.png' files if they exist - let _ = std::fs::remove_file(&new_path); - let _ = std::fs::remove_file(&diff_path); - new_image.save(&new_path).unwrap(); - diff_image.save(&diff_path).unwrap(); - panic!("Snapshot test '{test_name}' failed: Images are different"); + if std::env::var_os("MASONRY_TEST_BLESS").is_some_and(|it| !it.is_empty()) { + let _ = std::fs::remove_file(&new_path); + let _ = std::fs::remove_file(&diff_path); + new_image.save(&reference_path).unwrap(); + } else { + new_image.save(&new_path).unwrap(); + diff_image.save(&diff_path).unwrap(); + panic!("Snapshot test '{test_name}' failed: Images are different"); + } } else { // Remove the vestigial new and diff images let _ = std::fs::remove_file(&new_path);