Skip to content

Commit

Permalink
Improve snapshot error
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmerlin committed Sep 28, 2024
1 parent 2b2297d commit 62761d7
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions crates/egui_kittest/src/snapshot.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::fmt::Display;
use std::path::{Path, PathBuf};

#[derive(Debug)]
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit 62761d7

Please sign in to comment.