Skip to content

Commit

Permalink
Include name of failing kittest-test
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Dec 3, 2024
1 parent c18989e commit 3899a95
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions crates/egui_kittest/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ impl SnapshotOptions {
pub enum SnapshotError {
/// Image did not match snapshot
Diff {
/// Name of the test
name: String,

/// Count of pixels that were different
diff: i32,

Expand All @@ -72,6 +75,9 @@ pub enum SnapshotError {

/// The size of the image did not match the snapshot
SizeMismatch {
/// Name of the test
name: String,

/// Expected size
expected: (u32, u32),

Expand All @@ -92,10 +98,14 @@ pub enum SnapshotError {
impl Display for SnapshotError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Diff { diff, diff_path } => {
Self::Diff {
name,
diff,
diff_path,
} => {
write!(
f,
"Image did not match snapshot. Diff: {diff}, {diff_path:?}. Run `UPDATE_SNAPSHOTS=1 cargo test` to update the snapshots."
"'{name}' Image did not match snapshot. Diff: {diff}, {diff_path:?}. Run `UPDATE_SNAPSHOTS=1 cargo test` to update the snapshots."
)
}
Self::OpenSnapshot { path, err } => match err {
Expand All @@ -111,10 +121,14 @@ impl Display for SnapshotError {
write!(f, "Error decoding snapshot: {err:?}\nAt: {path:?}. Run `UPDATE_SNAPSHOTS=1 cargo test` to update the snapshots.")
}
},
Self::SizeMismatch { expected, actual } => {
Self::SizeMismatch {
name,
expected,
actual,
} => {
write!(
f,
"Image size did not match snapshot. Expected: {expected:?}, Actual: {actual:?}. Run `UPDATE_SNAPSHOTS=1 cargo test` to update the snapshots."
"'{name}' Image size did not match snapshot. Expected: {expected:?}, Actual: {actual:?}. Run `UPDATE_SNAPSHOTS=1 cargo test` to update the snapshots."
)
}
Self::WriteSnapshot { path, err } => {
Expand Down Expand Up @@ -194,6 +208,7 @@ pub fn try_image_snapshot_options(
if previous.dimensions() != current.dimensions() {
maybe_update_snapshot(&path, current)?;
return Err(SnapshotError::SizeMismatch {
name: name.to_owned(),
expected: previous.dimensions(),
actual: current.dimensions(),
});
Expand All @@ -217,13 +232,16 @@ pub fn try_image_snapshot_options(
err,
})?;
maybe_update_snapshot(&path, current)?;
return Err(SnapshotError::Diff { diff, diff_path });
Err(SnapshotError::Diff {
name: name.to_owned(),
diff,
diff_path,
})
} else {
// Delete old diff if it exists
std::fs::remove_file(diff_path).ok();
Ok(())
}

Ok(())
}

/// Image snapshot test.
Expand Down

0 comments on commit 3899a95

Please sign in to comment.