mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 14:50:03 -04:00
Add SnapshotResults struct to egui_kittest (#5672)
I got annoyed by all the slightly different variations of "collect snapshot results and unwrap them at the end of test" I've written, so I added a struct to make this nice and simple. One controversial thing: It panics when dropped. I wanted to ensure people cannot forget to unwrap the results at the end, and this was the best thing I could come up with. I don't think this is possible via clippy lint or something like that. * [x] I have followed the instructions in the PR template
This commit is contained in:
@@ -2,6 +2,7 @@ use egui::accesskit::Role;
|
||||
use egui::Vec2;
|
||||
use egui_demo_app::{Anchor, WrapApp};
|
||||
use egui_kittest::kittest::Queryable;
|
||||
use egui_kittest::SnapshotResults;
|
||||
|
||||
#[test]
|
||||
fn test_demo_app() {
|
||||
@@ -27,7 +28,7 @@ fn test_demo_app() {
|
||||
"Expected to find the Custom3d app.",
|
||||
);
|
||||
|
||||
let mut results = vec![];
|
||||
let mut results = SnapshotResults::new();
|
||||
|
||||
for (name, anchor) in apps {
|
||||
harness.get_by_role_and_label(Role::Button, name).click();
|
||||
@@ -68,12 +69,6 @@ fn test_demo_app() {
|
||||
// Can't use Harness::run because fractal clock keeps requesting repaints
|
||||
harness.run_steps(2);
|
||||
|
||||
if let Err(e) = harness.try_snapshot(&anchor.to_string()) {
|
||||
results.push(e);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(error) = results.first() {
|
||||
panic!("{error}");
|
||||
results.add(harness.try_snapshot(&anchor.to_string()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user