diff --git a/crates/egui_demo_lib/src/demo/demo_app_windows.rs b/crates/egui_demo_lib/src/demo/demo_app_windows.rs index 1c02951deb1..64d4d780995 100644 --- a/crates/egui_demo_lib/src/demo/demo_app_windows.rs +++ b/crates/egui_demo_lib/src/demo/demo_app_windows.rs @@ -397,7 +397,7 @@ mod tests { harness.set_size(Vec2::new(size.width as f32, size.height as f32)); // Run the app for some more frames... - harness.try_run().ok(); + harness.run_ok(); let mut options = SnapshotOptions::default(); // The Bézier Curve demo needs a threshold of 2.1 to pass on linux diff --git a/crates/egui_demo_lib/src/demo/modals.rs b/crates/egui_demo_lib/src/demo/modals.rs index c671e817842..833e07a28ed 100644 --- a/crates/egui_demo_lib/src/demo/modals.rs +++ b/crates/egui_demo_lib/src/demo/modals.rs @@ -183,12 +183,13 @@ mod tests { harness.get_by_role(Role::ComboBox).click(); - harness.try_run().ok(); + // Harness::run would fail because we keep requesting repaints to simulate progress. + harness.run_ok(); assert!(harness.ctx.memory(|mem| mem.any_popup_open())); assert!(harness.state().user_modal_open); harness.press_key(Key::Escape); - harness.try_run().ok(); + harness.run_ok(); assert!(!harness.ctx.memory(|mem| mem.any_popup_open())); assert!(harness.state().user_modal_open); } @@ -238,11 +239,11 @@ mod tests { results.push(harness.try_snapshot("modals_1")); harness.get_by_label("Save").click(); - harness.run_steps(3); + harness.run_ok(); results.push(harness.try_snapshot("modals_2")); harness.get_by_label("Yes Please").click(); - harness.run_steps(3); + harness.run_ok(); results.push(harness.try_snapshot("modals_3")); for result in results { @@ -266,11 +267,11 @@ mod tests { initial_state, ); - harness.run_steps(3); + harness.run_ok(); harness.get_by_label("Yes Please").simulate_click(); - harness.run_steps(2); + harness.run_ok(); // This snapshots should show the progress bar modal on top of the save modal. harness.snapshot("modals_backdrop_should_prevent_focusing_lower_area"); diff --git a/crates/egui_kittest/src/lib.rs b/crates/egui_kittest/src/lib.rs index f49bc4226b8..1737ac3d1f7 100644 --- a/crates/egui_kittest/src/lib.rs +++ b/crates/egui_kittest/src/lib.rs @@ -132,7 +132,7 @@ impl<'a, State> Harness<'a, State> { step_dt, }; // Run the harness until it is stable, ensuring that all Areas are shown and animations are done - harness.try_run().ok(); + harness.run_ok(); harness } @@ -259,7 +259,7 @@ impl<'a, State> Harness<'a, State> { if let Some(response) = &self.response { self.set_size(response.rect.size()); } - self.try_run().ok(); + self.run_ok(); } /// Run until @@ -274,6 +274,7 @@ impl<'a, State> Harness<'a, State> { /// /// See also: /// - [`Harness::try_run`]. + /// - [`Harness::run_ok`]. /// - [`Harness::step`]. /// - [`Harness::run_steps`]. #[track_caller] @@ -289,7 +290,7 @@ impl<'a, State> Harness<'a, State> { /// Run until /// - all animations are done /// - no more repaints are requested - /// - the maximum number of steps is reached + /// - the maximum number of steps is reached (See [`HarnessBuilder::with_max_steps`]) /// /// Returns the number of steps that were run. /// @@ -298,6 +299,7 @@ impl<'a, State> Harness<'a, State> { /// /// See also: /// - [`Harness::run`]. + /// - [`Harness::run_ok`]. /// - [`Harness::step`]. /// - [`Harness::run_steps`]. pub fn try_run(&mut self) -> Result { @@ -323,6 +325,22 @@ impl<'a, State> Harness<'a, State> { Ok(steps) } + /// Run until + /// - all animations are done + /// - no more repaints are requested + /// - the maximum number of steps is reached (See [`HarnessBuilder::with_max_steps`]) + /// + /// Returns the number of steps that were run, or None if the maximum number of steps was exceeded. + /// + /// See also: + /// - [`Harness::run`]. + /// - [`Harness::try_run`]. + /// - [`Harness::step`]. + /// - [`Harness::run_steps`]. + pub fn run_ok(&mut self) -> Option { + self.try_run().ok() + } + /// Run a number of steps. /// Equivalent to calling [`Harness::step`] x times. pub fn run_steps(&mut self, steps: usize) {