Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

gpui: Fix `TestWindow` panicking on `window_handle` (#62775)

goring7bddd16a09cf
diff --git a/crates/gpui/src/platform/test/window.rs b/crates/gpui/src/platform/test/window.rs
index dc96e43dfee..a3ae2ba20ba 100644
--- a/crates/gpui/src/platform/test/window.rs
+++ b/crates/gpui/src/platform/test/window.rs
@@ -48,11 +48,13 @@ pub(crate) struct TestWindowState {
#[derive(Clone)]
pub struct TestWindow(pub(crate) Rc<Mutex<TestWindowState>>);
+// Test windows are not backed by a real platform window, so there is no raw
+// handle to report; `NotSupported` is `raw_window_handle`'s variant for exactly this.
impl HasWindowHandle for TestWindow {
fn window_handle(
&self,
) -> Result<raw_window_handle::WindowHandle<'_>, raw_window_handle::HandleError> {
- unimplemented!("Test Windows are not backed by a real platform window")
+ Err(raw_window_handle::HandleError::NotSupported)
}
}
@@ -60,7 +62,7 @@ impl HasDisplayHandle for TestWindow {
fn display_handle(
&self,
) -> Result<raw_window_handle::DisplayHandle<'_>, raw_window_handle::HandleError> {
- unimplemented!("Test Windows are not backed by a real platform window")
+ Err(raw_window_handle::HandleError::NotSupported)
}
}
diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs
index 657e9bd7c18..fe40b9b7dee 100644
--- a/crates/gpui/src/window.rs
+++ b/crates/gpui/src/window.rs
@@ -6958,6 +6958,25 @@ mod tests {
);
}
+ #[gpui::test]
+ fn test_window_reports_no_raw_handle_instead_of_panicking(cx: &mut TestAppContext) {
+ use raw_window_handle::{HandleError, HasDisplayHandle as _, HasWindowHandle as _};
+
+ let window = cx.add_window(|_, _| EmptyView);
+ window
+ .update(cx, |_, window, _| {
+ assert!(matches!(
+ window.window_handle(),
+ Err(HandleError::NotSupported)
+ ));
+ assert!(matches!(
+ window.display_handle(),
+ Err(HandleError::NotSupported)
+ ));
+ })
+ .unwrap();
+ }
+
#[gpui::test]
fn test_appearance_change_runs_after_app_update(cx: &mut TestAppContext) {
let window = cx.add_window(|_, _| EmptyView);