diff --git a/crates/egui_kittest/src/lib.rs b/crates/egui_kittest/src/lib.rs index ef5e36f04..91b26bbc8 100644 --- a/crates/egui_kittest/src/lib.rs +++ b/crates/egui_kittest/src/lib.rs @@ -93,7 +93,7 @@ pub struct Harness<'a, State: 'static = ()> { #[cfg(feature = "snapshot")] default_snapshot_options: SnapshotOptions, #[cfg(feature = "snapshot")] - snapshot_results: Option, + snapshot_results: SnapshotResults, } impl Debug for Harness<'_, State> { @@ -185,7 +185,7 @@ impl<'a, State: 'static> Harness<'a, State> { default_snapshot_options, #[cfg(feature = "snapshot")] - snapshot_results: Some(SnapshotResults::default()), + snapshot_results: SnapshotResults::default(), }; // Run the harness until it is stable, ensuring that all Areas are shown and animations are done harness.run_ok(); @@ -934,12 +934,10 @@ impl Drop for Harness<'_, State> { fn drop(&mut self) { // Consume SnapshotResults first so its own panic-check runs under our control, // and so `std::thread::panicking()` reflects snapshot failures when plugins observe - // the final outcome. + // the final outcome. Drop may panic; if so, the panic propagates and plugins still + // see Fail. #[cfg(feature = "snapshot")] - if let Some(results) = self.snapshot_results.take() { - // Drop may panic; if so, the panic propagates and plugins still see Fail. - drop(results); - } + drop(std::mem::take(&mut self.snapshot_results)); if self.plugins.is_empty() { return; diff --git a/crates/egui_kittest/src/snapshot.rs b/crates/egui_kittest/src/snapshot.rs index 41e4912a4..4cc8db70e 100644 --- a/crates/egui_kittest/src/snapshot.rs +++ b/crates/egui_kittest/src/snapshot.rs @@ -675,10 +675,7 @@ impl Harness<'_, State> { #[track_caller] pub fn snapshot_options(&mut self, name: impl Into, options: &SnapshotOptions) { let result = self.try_snapshot_options(name, options); - self.snapshot_results - .as_mut() - .expect("SnapshotResults already taken") - .add(result); + self.snapshot_results.add(result); } /// Render an image using the setup [`crate::TestRenderer`] and compare it to the snapshot. @@ -695,10 +692,7 @@ impl Harness<'_, State> { #[track_caller] pub fn snapshot(&mut self, name: impl Into) { let result = self.try_snapshot(name); - self.snapshot_results - .as_mut() - .expect("SnapshotResults already taken") - .add(result); + self.snapshot_results.add(result); } /// Render a snapshot, save it to a temp file and open it in the default image viewer. @@ -751,10 +745,7 @@ impl Harness<'_, State> { /// This removes the snapshot results from the harness. Useful if you e.g. want to merge it /// with the results from another harness (using [`SnapshotResults::add`]). pub fn take_snapshot_results(&mut self) -> SnapshotResults { - // Replace with a fresh SnapshotResults so subsequent snapshot calls don't panic. - self.snapshot_results - .replace(SnapshotResults::default()) - .expect("SnapshotResults already taken") + std::mem::take(&mut self.snapshot_results) } }