mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 04:40: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:
@@ -84,6 +84,8 @@ pub struct Harness<'a, State = ()> {
|
||||
|
||||
#[cfg(feature = "snapshot")]
|
||||
default_snapshot_options: SnapshotOptions,
|
||||
#[cfg(feature = "snapshot")]
|
||||
snapshot_results: SnapshotResults,
|
||||
}
|
||||
|
||||
impl<State> Debug for Harness<'_, State> {
|
||||
@@ -93,6 +95,7 @@ impl<State> Debug for Harness<'_, State> {
|
||||
}
|
||||
|
||||
impl<'a, State> Harness<'a, State> {
|
||||
#[track_caller]
|
||||
pub(crate) fn from_builder(
|
||||
builder: HarnessBuilder<State>,
|
||||
mut app: AppKind<'a, State>,
|
||||
@@ -162,6 +165,9 @@ impl<'a, State> Harness<'a, State> {
|
||||
|
||||
#[cfg(feature = "snapshot")]
|
||||
default_snapshot_options,
|
||||
|
||||
#[cfg(feature = "snapshot")]
|
||||
snapshot_results: SnapshotResults::default(),
|
||||
};
|
||||
// Run the harness until it is stable, ensuring that all Areas are shown and animations are done
|
||||
harness.run_ok();
|
||||
@@ -197,6 +203,7 @@ impl<'a, State> Harness<'a, State> {
|
||||
///
|
||||
/// assert_eq!(*harness.state(), true);
|
||||
/// ```
|
||||
#[track_caller]
|
||||
pub fn new_state(app: impl FnMut(&egui::Context, &mut State) + 'a, state: State) -> Self {
|
||||
Self::builder().build_state(app, state)
|
||||
}
|
||||
@@ -222,12 +229,14 @@ impl<'a, State> Harness<'a, State> {
|
||||
///
|
||||
/// assert_eq!(*harness.state(), true);
|
||||
/// ```
|
||||
#[track_caller]
|
||||
pub fn new_ui_state(app: impl FnMut(&mut egui::Ui, &mut State) + 'a, state: State) -> Self {
|
||||
Self::builder().build_ui_state(app, state)
|
||||
}
|
||||
|
||||
/// Create a new [Harness] from the given eframe creation closure.
|
||||
#[cfg(feature = "eframe")]
|
||||
#[track_caller]
|
||||
pub fn new_eframe(builder: impl FnOnce(&mut eframe::CreationContext<'a>) -> State) -> Self
|
||||
where
|
||||
State: eframe::App,
|
||||
@@ -725,6 +734,7 @@ impl<'a> Harness<'a> {
|
||||
/// });
|
||||
/// });
|
||||
/// ```
|
||||
#[track_caller]
|
||||
pub fn new(app: impl FnMut(&egui::Context) + 'a) -> Self {
|
||||
Self::builder().build(app)
|
||||
}
|
||||
@@ -745,6 +755,7 @@ impl<'a> Harness<'a> {
|
||||
/// ui.label("Hello, world!");
|
||||
/// });
|
||||
/// ```
|
||||
#[track_caller]
|
||||
pub fn new_ui(app: impl FnMut(&mut egui::Ui) + 'a) -> Self {
|
||||
Self::builder().build_ui(app)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user