1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-31 22:00:03 -04:00

Enforce consistent snapshot updates (#7744)

* Closes https://github.com/emilk/egui/issues/7647


This collects SnapshotResults within the Harness and adds a check to
enforce snapshot results are merged in case multiple Harnesses are
constructed within a test.

This should make snapshot updates via kitdiff/accept_snapshots.sh way
more useful since it should now always update all snapshots instead of
only the first one per test.
This commit is contained in:
Lucas Meurer
2025-11-26 14:56:19 +01:00
committed by GitHub
parent a19629ef4a
commit de907612b7
7 changed files with 100 additions and 17 deletions

View File

@@ -166,6 +166,7 @@ impl<State> HarnessBuilder<State> {
///
/// assert_eq!(*harness.state(), true);
/// ```
#[track_caller]
pub fn build_state<'a>(
self,
app: impl FnMut(&egui::Context, &mut State) + 'a,
@@ -195,6 +196,7 @@ impl<State> HarnessBuilder<State> {
///
/// assert_eq!(*harness.state(), true);
/// ```
#[track_caller]
pub fn build_ui_state<'a>(
self,
app: impl FnMut(&mut egui::Ui, &mut State) + 'a,
@@ -206,6 +208,7 @@ impl<State> HarnessBuilder<State> {
/// Create a new [Harness] from the given eframe creation closure.
/// The app can be accessed via the [`Harness::state`] / [`Harness::state_mut`] methods.
#[cfg(feature = "eframe")]
#[track_caller]
pub fn build_eframe<'a>(
self,
build: impl FnOnce(&mut eframe::CreationContext<'a>) -> State,
@@ -247,6 +250,7 @@ impl HarnessBuilder {
/// });
/// ```
#[must_use]
#[track_caller]
pub fn build<'a>(self, app: impl FnMut(&egui::Context) + 'a) -> Harness<'a> {
Harness::from_builder(self, AppKind::Context(Box::new(app)), (), None)
}
@@ -267,6 +271,7 @@ impl HarnessBuilder {
/// });
/// ```
#[must_use]
#[track_caller]
pub fn build_ui<'a>(self, app: impl FnMut(&mut egui::Ui) + 'a) -> Harness<'a> {
Harness::from_builder(self, AppKind::Ui(Box::new(app)), (), None)
}