Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug kittest tests with eframe #5418

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,7 @@ version = "0.29.1"
dependencies = [
"dify",
"document-features",
"eframe",
"egui",
"egui-wgpu",
"egui_kittest",
Expand Down
5 changes: 5 additions & 0 deletions crates/egui_kittest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@ wgpu = ["dep:egui-wgpu", "dep:pollster", "dep:image"]
# Adds a dify-based image snapshot utility.
snapshot = ["dep:dify", "dep:image", "image/png"]

# Allows debugging tests via eframe.
run_with_eframe = ["dep:eframe"]

default = ["eframe?/wgpu"]

[dependencies]
kittest.workspace = true
egui = { workspace = true, features = ["accesskit"] }
eframe = { workspace = true, features = ["accesskit"], optional = true }

# wgpu dependencies
egui-wgpu = { workspace = true, optional = true }
Expand Down
17 changes: 16 additions & 1 deletion crates/egui_kittest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ mod snapshot;
pub use snapshot::*;
use std::fmt::{Debug, Formatter};
mod app_kind;
#[cfg(feature = "run_with_eframe")]
mod run_with_eframe;
#[cfg(feature = "wgpu")]
mod texture_to_image;
#[cfg(feature = "wgpu")]
Expand All @@ -23,7 +25,7 @@ use std::mem;
use crate::app_kind::AppKind;
use crate::event::EventState;
pub use builder::*;
use egui::{Pos2, Rect, TexturesDelta, Vec2, ViewportId};
use egui::{Pos2, Rect, TexturesDelta, Vec2, ViewportBuilder, ViewportId};
use kittest::{Node, Queryable};

/// The test Harness. This contains everything needed to run the test.
Expand Down Expand Up @@ -268,6 +270,19 @@ impl<'a, State> Harness<'a, State> {
physical_key: None,
});
}

#[cfg(feature = "run_with_eframe")]
pub fn run_with_eframe(&mut self) {
let native_options = eframe::NativeOptions {
viewport: ViewportBuilder::default().with_inner_size(self.ctx.screen_rect().size()),
..Default::default()
};
eframe::run_native(
"egui_debug",
native_options,
Box::new(|cc| Ok(Box::new(self))),
);
}
}

/// Utilities for stateless harnesses.
Expand Down
13 changes: 13 additions & 0 deletions crates/egui_kittest/src/run_with_eframe.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use crate::Harness;
use eframe::Frame;
use egui::Context;

impl<'a, State> eframe::App for &mut Harness<'a, State> {
fn update(&mut self, ctx: &Context, frame: &mut Frame) {
self.app.run(ctx, &mut self.state, false);
}

fn persist_egui_memory(&self) -> bool {
false
}
}
2 changes: 2 additions & 0 deletions crates/egui_kittest/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ fn test_shrink() {

harness.fit_contents();

harness.run_with_eframe();

harness.wgpu_snapshot("test_shrink");
}
Loading