From 62761d7db717ebf3c547beb28ef47d2a1c313b8b Mon Sep 17 00:00:00 2001 From: Lucas Meurer Date: Sun, 29 Sep 2024 01:20:29 +0200 Subject: [PATCH] Improve snapshot error --- crates/egui_kittest/src/snapshot.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/crates/egui_kittest/src/snapshot.rs b/crates/egui_kittest/src/snapshot.rs index f93868bfb760..80cc78b947be 100644 --- a/crates/egui_kittest/src/snapshot.rs +++ b/crates/egui_kittest/src/snapshot.rs @@ -1,3 +1,4 @@ +use std::fmt::Display; use std::path::{Path, PathBuf}; #[derive(Debug)] @@ -6,6 +7,16 @@ pub struct SnapshotError { pub diff_path: PathBuf, } +impl Display for SnapshotError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "Image did not match snapshot. Diff: {}, {:?}", + self.diff, self.diff_path + ) + } +} + /// Image snapshot test. /// /// # Errors @@ -65,10 +76,7 @@ pub fn image_snapshot(current: image::RgbaImage, name: &str) { match try_image_snapshot(current, name) { Ok(_) => {} Err(err) => { - panic!( - "{name} failed. Image did not match snapshot. Diff: {}, {:?}", - err.diff, err.diff_path - ); + panic!("{}", err); } } }