diff --git a/gpui/src/app.rs b/gpui/src/app.rs index 6aac020daf..decf659561 100644 --- a/gpui/src/app.rs +++ b/gpui/src/app.rs @@ -111,10 +111,7 @@ pub struct TestAppContext { } impl App { - pub fn test T>( - asset_source: A, - f: F, - ) -> T { + pub fn test T>(f: F) -> T { let foreground_platform = platform::test::foreground_platform(); let platform = platform::test::platform(); let foreground = Rc::new(executor::Foreground::test()); @@ -122,32 +119,20 @@ impl App { foreground, Arc::new(platform), Rc::new(foreground_platform), - asset_source, + (), ))); cx.borrow_mut().weak_self = Some(Rc::downgrade(&cx)); let mut cx = cx.borrow_mut(); f(&mut *cx) } - pub fn test_async(asset_source: A, f: Fn) -> T + pub fn test_async(f: Fn) -> T where Fn: FnOnce(TestAppContext) -> F, F: Future, { - let platform = Arc::new(platform::test::platform()); - let foreground_platform = Rc::new(platform::test::foreground_platform()); let foreground = Rc::new(executor::Foreground::test()); - let cx = TestAppContext { - cx: Rc::new(RefCell::new(MutableAppContext::new( - foreground.clone(), - platform, - foreground_platform.clone(), - asset_source, - ))), - foreground_platform, - }; - cx.cx.borrow_mut().weak_self = Some(Rc::downgrade(&cx.cx)); - + let cx = TestAppContext::new(foreground.clone()); let future = f(cx); smol::block_on(foreground.run(future)) } @@ -261,6 +246,22 @@ impl App { } impl TestAppContext { + pub fn new(foreground: Rc) -> Self { + let platform = Arc::new(platform::test::platform()); + let foreground_platform = Rc::new(platform::test::foreground_platform()); + let cx = TestAppContext { + cx: Rc::new(RefCell::new(MutableAppContext::new( + foreground.clone(), + platform, + foreground_platform.clone(), + (), + ))), + foreground_platform, + }; + cx.cx.borrow_mut().weak_self = Some(Rc::downgrade(&cx.cx)); + cx + } + pub fn dispatch_action( &self, window_id: usize, diff --git a/gpui_macros/src/lib.rs b/gpui_macros/src/lib.rs index c7218387df..12c86b69bd 100644 --- a/gpui_macros/src/lib.rs +++ b/gpui_macros/src/lib.rs @@ -34,7 +34,7 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream { fn #outer_fn_name() { #inner_fn - #namespace::App::test_async((), move |cx| async { + #namespace::App::test_async(move |cx| async { #inner_fn_name(cx).await; }); } @@ -45,7 +45,7 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream { fn #outer_fn_name() { #inner_fn - #namespace::App::test((), |cx| { + #namespace::App::test(|cx| { #inner_fn_name(cx); }); }