WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 32336e2

Browse files
authored
Write .new.png file if snapshot is missing (#7610)
We should write the .new.png whenever the test fails and snapshots aren't updated. Necessary for the kitdiff-snapshot-update-workflow to work
1 parent 9e13889 commit 32336e2

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

crates/egui_kittest/src/snapshot.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -397,13 +397,24 @@ fn try_image_snapshot_options_impl(
397397
Ok(())
398398
};
399399

400+
let write_new_png = || {
401+
new.save(&new_path)
402+
.map_err(|err| SnapshotError::WriteSnapshot {
403+
err,
404+
path: new_path.clone(),
405+
})?;
406+
Ok(())
407+
};
408+
400409
let previous = match image::open(&snapshot_path) {
401410
Ok(image) => image.to_rgba8(),
402411
Err(err) => {
403-
// No previous snapshot - probablye a new test.
412+
// No previous snapshot - probably a new test.
404413
if mode.is_update() {
405414
return update_snapshot();
406415
} else {
416+
write_new_png()?;
417+
407418
return Err(SnapshotError::OpenSnapshot {
408419
path: snapshot_path.clone(),
409420
err,
@@ -416,6 +427,8 @@ fn try_image_snapshot_options_impl(
416427
if mode.is_update() {
417428
return update_snapshot();
418429
} else {
430+
write_new_png()?;
431+
419432
return Err(SnapshotError::SizeMismatch {
420433
name,
421434
expected: previous.dimensions(),
@@ -454,11 +467,7 @@ fn try_image_snapshot_options_impl(
454467
if below_threshold {
455468
Ok(())
456469
} else {
457-
new.save(&new_path)
458-
.map_err(|err| SnapshotError::WriteSnapshot {
459-
err,
460-
path: new_path.clone(),
461-
})?;
470+
write_new_png()?;
462471

463472
Err(SnapshotError::Diff {
464473
name,

0 commit comments

Comments
 (0)