Use quit to end tests

Conrad Irwin created

Change summary

crates/gpui2/src/app.rs                 |  2 ++
crates/gpui2/src/app/test_context.rs    |  8 ++------
crates/gpui2/src/platform/mac/window.rs |  2 +-
crates/gpui2_macros/src/test.rs         | 16 +++++-----------
4 files changed, 10 insertions(+), 18 deletions(-)

Detailed changes

crates/gpui2/src/app.rs 🔗

@@ -224,6 +224,8 @@ impl AppContext {
         {
             log::error!("timed out waiting on app_will_quit");
         }
+
+        self.globals_by_type.clear();
     }
 
     pub fn app_metadata(&self) -> AppMetadata {

crates/gpui2/src/app/test_context.rs 🔗

@@ -48,12 +48,8 @@ impl TestAppContext {
         }
     }
 
-    pub fn remove_all_windows(&self) {
-        // todo!("use app quit instead")
-    }
-
-    pub fn clear_globals(&self) {
-        // todo!("use app quit instead")
+    pub fn quit(&self) {
+        self.app.lock().quit();
     }
 
     pub fn refresh(&mut self) -> Result<()> {

crates/gpui2/src/platform/mac/window.rs 🔗

@@ -1,6 +1,6 @@
 use super::{display_bounds_from_native, ns_string, MacDisplay, MetalRenderer, NSRange};
 use crate::{
-    display_bounds_to_native, point, px, size, AnyWindowHandle, Bounds, ExternalPaths, Executor,
+    display_bounds_to_native, point, px, size, AnyWindowHandle, Bounds, Executor, ExternalPaths,
     FileDropEvent, GlobalPixels, InputEvent, KeyDownEvent, Keystroke, Modifiers,
     ModifiersChangedEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, Pixels,
     PlatformAtlas, PlatformDisplay, PlatformInputHandler, PlatformWindow, Point, Scene, Size,

crates/gpui2_macros/src/test.rs 🔗

@@ -3,8 +3,8 @@ use proc_macro2::Ident;
 use quote::{format_ident, quote};
 use std::mem;
 use syn::{
-    parse_macro_input, parse_quote, spanned::Spanned as _, AttributeArgs, FnArg,
-    ItemFn, Lit, Meta, NestedMeta, Type,
+    parse_macro_input, parse_quote, spanned::Spanned as _, AttributeArgs, FnArg, ItemFn, Lit, Meta,
+    NestedMeta, Type,
 };
 
 pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {
@@ -110,9 +110,7 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {
                                 );
                             ));
                             cx_teardowns.extend(quote!(
-                                #cx_varname.remove_all_windows();
-                                dispatcher.run_until_parked();
-                                #cx_varname.clear_globals();
+                                #cx_varname.quit();
                                 dispatcher.run_until_parked();
                             ));
                             inner_fn_args.extend(quote!(&mut #cx_varname,));
@@ -176,9 +174,7 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {
                                 ));
                                 inner_fn_args.extend(quote!(&mut #cx_varname_lock,));
                                 cx_teardowns.extend(quote!(
-                                    #cx_varname.remove_all_windows();
-                                    dispatcher.run_until_parked();
-                                    #cx_varname.clear_globals();
+                                    #cx_varname.quit();
                                     dispatcher.run_until_parked();
                                 ));
                                 continue;
@@ -191,9 +187,7 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {
                                     );
                                 ));
                                 cx_teardowns.extend(quote!(
-                                    #cx_varname.remove_all_windows();
-                                    dispatcher.run_until_parked();
-                                    #cx_varname.clear_globals();
+                                    #cx_varname.quit();
                                     dispatcher.run_until_parked();
                                 ));
                                 inner_fn_args.extend(quote!(&mut #cx_varname,));