mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 04:40:03 -04:00
Add Harness::spawn_eframe_app (#8120)
This lets you start up the test app from within the test itself, which can be very useful when you have a specific test scenario set up that you need to debug. ### Related * Previous attempt: https://github.com/emilk/egui/pull/5418 ### macOS On macOS, you may only run UIs on the main loop, so you need a few additional steps. Not ideal, but works! ```diff diff --git a/crates/egui_demo_app/Cargo.toml b/crates/egui_demo_app/Cargo.toml index f9a153268..4e0cc14ee 100644 --- a/crates/egui_demo_app/Cargo.toml +++ b/crates/egui_demo_app/Cargo.toml @@ -84,3 +84,7 @@ web-sys.workspace = true [dev-dependencies] egui_kittest = { workspace = true, features = ["eframe", "snapshot", "wgpu"] } + +[[test]] +name = "test_demo_app" +harness = false diff --git a/crates/egui_demo_app/tests/test_demo_app.rs b/crates/egui_demo_app/tests/test_demo_app.rs index e083c8455..7ad9ed516 100644 --- a/crates/egui_demo_app/tests/test_demo_app.rs +++ b/crates/egui_demo_app/tests/test_demo_app.rs @@ -4,7 +4,10 @@ use egui_demo_app::{Anchor, WrapApp}; use egui_kittest::SnapshotResults; use egui_kittest::kittest::Queryable as _; -#[test] +fn main() { + test_demo_app(); +} + fn test_demo_app() { let mut harness = egui_kittest::Harness::builder() .with_size(Vec2::new(900.0, 600.0)) @@ -73,5 +76,8 @@ fn test_demo_app() { harness.run_steps(4); results.add(harness.try_snapshot(anchor.to_string())); + + harness.spawn_eframe_app(); + break; } } ```
This commit is contained in:
@@ -55,6 +55,10 @@ pub struct GlowWinitApp<'app> {
|
||||
// re-initializing the `GlowWinitRunning` state on Android if the application
|
||||
// suspends and resumes.
|
||||
app_creator: Option<AppCreator<'app>>,
|
||||
|
||||
/// An optional pre-existing egui context. If `Some`, it is used instead of
|
||||
/// creating a new one via [`create_egui_context`]. Taken during initialization.
|
||||
egui_ctx: Option<egui::Context>,
|
||||
}
|
||||
|
||||
/// State that is initialized when the application is first starts running via
|
||||
@@ -128,6 +132,7 @@ impl<'app> GlowWinitApp<'app> {
|
||||
event_loop: &EventLoop<UserEvent>,
|
||||
app_name: &str,
|
||||
native_options: NativeOptions,
|
||||
egui_ctx: Option<egui::Context>,
|
||||
app_creator: AppCreator<'app>,
|
||||
) -> Self {
|
||||
profiling::function_scope!();
|
||||
@@ -137,6 +142,7 @@ impl<'app> GlowWinitApp<'app> {
|
||||
native_options,
|
||||
running: None,
|
||||
app_creator: Some(app_creator),
|
||||
egui_ctx,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,7 +215,10 @@ impl<'app> GlowWinitApp<'app> {
|
||||
)
|
||||
};
|
||||
|
||||
let egui_ctx = create_egui_context(storage.as_deref());
|
||||
let egui_ctx = self
|
||||
.egui_ctx
|
||||
.take()
|
||||
.unwrap_or_else(|| create_egui_context(storage.as_deref()));
|
||||
|
||||
let (mut glutin, painter) = Self::create_glutin_windowed_context(
|
||||
&egui_ctx,
|
||||
|
||||
Reference in New Issue
Block a user