Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

fix(ui-egui): GPU canvas tests no longer read a setup failure as "no GPU adapter" (#854)

Luna1d78668b258c
diff --git a/crates/ui-egui/tests/canvas_16f.rs b/crates/ui-egui/tests/canvas_16f.rs
index 028ed2576..3c296a3bd 100644
--- a/crates/ui-egui/tests/canvas_16f.rs
+++ b/crates/ui-egui/tests/canvas_16f.rs
@@ -195,9 +195,6 @@ fn screen(doc: Document, setup: &[(&str, serde_json::Value)], name: &str) -> Opt
app.set_wgpu(rs.clone());
}
app.session.open_document(doc, None);
- for (id, p) in setup {
- app.run(&id, p).expect("setup command");
- }
app
})
}));
@@ -209,6 +206,11 @@ fn screen(doc: Document, setup: &[(&str, serde_json::Value)], name: &str) -> Opt
eprintln!("skipping: adapter can't render/filter Rgba16Float");
return None;
}
+ // Outside the catch_unwind: a failing setup command fails the test instead of reading as
+ // "no GPU adapter" (#760).
+ for (id, p) in setup {
+ harness.state_mut().run(&id, p).unwrap_or_else(|e| panic!("setup command {id}: {e}"));
+ }
harness.run_steps(6);
let img = harness.render().expect("render");
let out = std::env::temp_dir().join(name);
diff --git a/crates/ui-egui/tests/color_managed_canvas.rs b/crates/ui-egui/tests/color_managed_canvas.rs
index b1ff92dd8..81fa89845 100644
--- a/crates/ui-egui/tests/color_managed_canvas.rs
+++ b/crates/ui-egui/tests/color_managed_canvas.rs
@@ -16,7 +16,6 @@ fn render(profile: &str, rgb: [f32; 3], reopen: bool) -> Option<([u8; 3], [u8; 3
let ft = float_targets.clone();
let observer = Arc::new(std::sync::Mutex::new(None));
let observer_out = observer.clone();
- let profile = profile.to_string();
let built = std::panic::catch_unwind(std::panic::AssertUnwindSafe(move || {
egui_kittest::Harness::builder().with_size(egui::vec2(1000.0, 700.0)).with_pixels_per_point(1.0).with_max_steps(64).wgpu().build_eframe(move |cc| {
PhotocraftApp::setup_context(&cc.egui_ctx, Default::default());
@@ -26,14 +25,6 @@ fn render(profile: &str, rgb: [f32; 3], reopen: bool) -> Option<([u8; 3], [u8; 3
*observer_out.lock().expect("GPU observer lock") = Some(photocraft_ui_egui::gpu_canvas::GpuCanvas::new(rs));
app.set_wgpu(rs.clone());
}
- let hex = format!("#{:02x}{:02x}{:02x}", (rgb[0] * 255.0).round() as u8, (rgb[1] * 255.0).round() as u8, (rgb[2] * 255.0).round() as u8);
- app.run("file.new", json!({"width": 512, "height": 512, "mode": "rgb", "depth": 8})).expect("new");
- app.run("edit.assignProfile", json!({"profile": profile})).expect("assign");
- app.run("edit.fill", json!({"color": hex})).expect("fill");
- // Native loading starts at revision one; preserve that collision in the reopen case.
- if reopen {
- app.session.active_mut().unwrap().revision = 1;
- }
app
})
}));
@@ -45,6 +36,17 @@ fn render(profile: &str, rgb: [f32; 3], reopen: bool) -> Option<([u8; 3], [u8; 3
eprintln!("skipping: adapter can't render Rgba32Float");
return None;
}
+ // Outside the catch_unwind: a failing setup command fails the test instead of reading as
+ // "no GPU adapter" (#760).
+ let hex = format!("#{:02x}{:02x}{:02x}", (rgb[0] * 255.0).round() as u8, (rgb[1] * 255.0).round() as u8, (rgb[2] * 255.0).round() as u8);
+ let app = harness.state_mut();
+ app.run("file.new", json!({"width": 512, "height": 512, "mode": "rgb", "depth": 8})).expect("new");
+ app.run("edit.assignProfile", json!({"profile": profile})).expect("assign");
+ app.run("edit.fill", json!({"color": hex})).expect("fill");
+ // Native loading starts at revision one; preserve that collision in the reopen case.
+ if reopen {
+ app.session.active_mut().expect("active document").revision = 1;
+ }
let sample = |harness: &mut egui_kittest::Harness<'_, PhotocraftApp>| {
harness.run_steps(6);
let img = harness.render().expect("render");