From ab5db0bc1e5b6b54f523db9e240961fc9725d97b Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Sat, 18 Dec 2021 11:06:07 -0700 Subject: [PATCH] Fix warnings and tests --- crates/gpui/src/app.rs | 9 ++---- crates/server/src/rpc.rs | 3 +- crates/zed/src/test.rs | 2 +- crates/zed/src/zed.rs | 68 +++++++++++++++++++++++++--------------- 4 files changed, 47 insertions(+), 35 deletions(-) diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index f5c947019f..dd9e09f663 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -3992,12 +3992,7 @@ mod tests { let actions_clone = actions.clone(); cx.add_global_action(move |_: &Action, _: &mut MutableAppContext| { - actions_clone.borrow_mut().push("global a".to_string()); - }); - - let actions_clone = actions.clone(); - cx.add_global_action(move |_: &Action, _: &mut MutableAppContext| { - actions_clone.borrow_mut().push("global b".to_string()); + actions_clone.borrow_mut().push("global".to_string()); }); let actions_clone = actions.clone(); @@ -4053,7 +4048,7 @@ mod tests { assert_eq!( *actions.borrow(), - vec!["4 d", "4 c", "3 b", "3 a", "2 d", "2 c", "global b", "global a"] + vec!["4 d", "4 c", "3 b", "3 a", "2 d", "2 c", "global"] ); } diff --git a/crates/server/src/rpc.rs b/crates/server/src/rpc.rs index 96949d05ff..5febe696c6 100644 --- a/crates/server/src/rpc.rs +++ b/crates/server/src/rpc.rs @@ -1153,7 +1153,8 @@ mod tests { ) }) .unwrap() - .await; + .await + .unwrap(); workspace_b.read_with(&cx_b, |workspace, cx| { let active_pane = workspace.active_pane().read(cx); assert!(active_pane.active_item().is_some()); diff --git a/crates/zed/src/test.rs b/crates/zed/src/test.rs index a495b2689d..fa540ae72a 100644 --- a/crates/zed/src/test.rs +++ b/crates/zed/src/test.rs @@ -1,4 +1,4 @@ -use crate::{assets::Assets, build_window_options, AppState, build_workspace}; +use crate::{assets::Assets, build_window_options, build_workspace, AppState}; use client::{http::ServerResponse, test::FakeHttpClient, ChannelList, Client, UserStore}; use gpui::{AssetSource, MutableAppContext}; use language::LanguageRegistry; diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index 3c3f4f7f45..ad543ee166 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -31,7 +31,6 @@ const MIN_FONT_SIZE: f32 = 6.0; pub fn init(app_state: &Arc, cx: &mut gpui::MutableAppContext) { cx.add_global_action(quit); - cx.add_global_action({ let settings_tx = app_state.settings_tx.clone(); @@ -175,7 +174,9 @@ mod tests { #[gpui::test] async fn test_new_empty_workspace(mut cx: gpui::TestAppContext) { let app_state = cx.update(test_app_state); - cx.update(|cx| init(&app_state, cx)); + cx.update(|cx| { + workspace::init(cx); + }); cx.dispatch_global_action(workspace::OpenNew(app_state.clone())); let window_id = *cx.window_ids().first().unwrap(); let workspace = cx.root_view::(window_id).unwrap(); @@ -241,10 +242,11 @@ mod tests { let file3 = entries[2].clone(); // Open the first entry - workspace + let entry_1 = workspace .update(&mut cx, |w, cx| w.open_entry(file1.clone(), cx)) .unwrap() - .await; + .await + .unwrap(); cx.read(|cx| { let pane = workspace.read(cx).active_pane().read(cx); assert_eq!( @@ -258,7 +260,8 @@ mod tests { workspace .update(&mut cx, |w, cx| w.open_entry(file2.clone(), cx)) .unwrap() - .await; + .await + .unwrap(); cx.read(|cx| { let pane = workspace.read(cx).active_pane().read(cx); assert_eq!( @@ -269,9 +272,12 @@ mod tests { }); // Open the first entry again. The existing pane item is activated. - workspace.update(&mut cx, |w, cx| { - assert!(w.open_entry(file1.clone(), cx).is_none()) - }); + let entry_1b = workspace + .update(&mut cx, |w, cx| w.open_entry(file1.clone(), cx).unwrap()) + .await + .unwrap(); + assert_eq!(entry_1.id(), entry_1b.id()); + cx.read(|cx| { let pane = workspace.read(cx).active_pane().read(cx); assert_eq!( @@ -282,9 +288,15 @@ mod tests { }); // Split the pane with the first entry, then open the second entry again. - workspace.update(&mut cx, |w, cx| { - w.split_pane(w.active_pane().clone(), SplitDirection::Right, cx); - assert!(w.open_entry(file2.clone(), cx).is_none()); + workspace + .update(&mut cx, |w, cx| { + w.split_pane(w.active_pane().clone(), SplitDirection::Right, cx); + w.open_entry(file2.clone(), cx).unwrap() + }) + .await + .unwrap(); + + workspace.read_with(&cx, |w, cx| { assert_eq!( w.active_pane() .read(cx) @@ -302,8 +314,8 @@ mod tests { w.open_entry(file3.clone(), cx).unwrap(), ) }); - t1.await; - t2.await; + t1.await.unwrap(); + t2.await.unwrap(); cx.read(|cx| { let pane = workspace.read(cx).active_pane().read(cx); assert_eq!( @@ -524,18 +536,21 @@ mod tests { // Open the same newly-created file in another pane item. The new editor should reuse // the same buffer. cx.dispatch_action(window_id, vec![workspace.id()], OpenNew(app_state.clone())); - workspace.update(&mut cx, |workspace, cx| { - workspace.split_pane(workspace.active_pane().clone(), SplitDirection::Right, cx); - assert!(workspace - .open_entry( - ProjectPath { - worktree_id: worktree.id(), - path: Path::new("the-new-name.rs").into() - }, - cx - ) - .is_none()); - }); + workspace + .update(&mut cx, |workspace, cx| { + workspace.split_pane(workspace.active_pane().clone(), SplitDirection::Right, cx); + workspace + .open_entry( + ProjectPath { + worktree_id: worktree.id(), + path: Path::new("the-new-name.rs").into(), + }, + cx, + ) + .unwrap() + }) + .await + .unwrap(); let editor2 = workspace.update(&mut cx, |workspace, cx| { workspace .active_item(cx) @@ -631,7 +646,8 @@ mod tests { workspace .update(&mut cx, |w, cx| w.open_entry(file1.clone(), cx)) .unwrap() - .await; + .await + .unwrap(); cx.read(|cx| { assert_eq!( pane_1.read(cx).active_item().unwrap().project_path(cx),