windows: Fix tests on Windows (#22616)

Release Notes:

- N/A

---------

Co-authored-by: Mikayla <mikayla.c.maki@gmail.com>
This commit is contained in:
张小白 2025-02-05 22:30:09 +08:00 committed by GitHub
parent c252b5db16
commit 74c4dbd237
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
56 changed files with 1540 additions and 856 deletions

View file

@ -6,6 +6,7 @@ use gpui::{Entity, TestAppContext, VisualTestContext};
use menu::{Confirm, SelectNext, SelectPrev};
use project::{RemoveOptions, FS_WATCH_LATENCY};
use serde_json::json;
use util::path;
use workspace::{AppState, ToggleFileFinder, Workspace};
#[ctor::ctor]
@ -90,7 +91,7 @@ async fn test_absolute_paths(cx: &mut TestAppContext) {
.fs
.as_fake()
.insert_tree(
"/root",
path!("/root"),
json!({
"a": {
"file1.txt": "",
@ -102,16 +103,16 @@ async fn test_absolute_paths(cx: &mut TestAppContext) {
)
.await;
let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;
let project = Project::test(app_state.fs.clone(), [path!("/root").as_ref()], cx).await;
let (picker, workspace, cx) = build_find_picker(project, cx);
let matching_abs_path = "/root/a/b/file2.txt";
let matching_abs_path = path!("/root/a/b/file2.txt").to_string();
picker
.update_in(cx, |picker, window, cx| {
picker
.delegate
.update_matches(matching_abs_path.to_string(), window, cx)
.update_matches(matching_abs_path, window, cx)
})
.await;
picker.update(cx, |picker, _| {
@ -128,12 +129,12 @@ async fn test_absolute_paths(cx: &mut TestAppContext) {
assert_eq!(active_editor.read(cx).title(cx), "file2.txt");
});
let mismatching_abs_path = "/root/a/b/file1.txt";
let mismatching_abs_path = path!("/root/a/b/file1.txt").to_string();
picker
.update_in(cx, |picker, window, cx| {
picker
.delegate
.update_matches(mismatching_abs_path.to_string(), window, cx)
.update_matches(mismatching_abs_path, window, cx)
})
.await;
picker.update(cx, |picker, _| {
@ -518,7 +519,7 @@ async fn test_path_distance_ordering(cx: &mut TestAppContext) {
.fs
.as_fake()
.insert_tree(
"/root",
path!("/root"),
json!({
"dir1": { "a.txt": "" },
"dir2": {
@ -529,7 +530,7 @@ async fn test_path_distance_ordering(cx: &mut TestAppContext) {
)
.await;
let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;
let project = Project::test(app_state.fs.clone(), [path!("/root").as_ref()], cx).await;
let (workspace, cx) = cx.add_window_view(|window, cx| Workspace::test_new(project, window, cx));
let worktree_id = cx.read(|cx| {
@ -606,7 +607,7 @@ async fn test_query_history(cx: &mut gpui::TestAppContext) {
.fs
.as_fake()
.insert_tree(
"/src",
path!("/src"),
json!({
"test": {
"first.rs": "// First Rust file",
@ -617,7 +618,7 @@ async fn test_query_history(cx: &mut gpui::TestAppContext) {
)
.await;
let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;
let project = Project::test(app_state.fs.clone(), [path!("/src").as_ref()], cx).await;
let (workspace, cx) = cx.add_window_view(|window, cx| Workspace::test_new(project, window, cx));
let worktree_id = cx.read(|cx| {
let worktrees = workspace.read(cx).worktrees(cx).collect::<Vec<_>>();
@ -648,7 +649,7 @@ async fn test_query_history(cx: &mut gpui::TestAppContext) {
worktree_id,
path: Arc::from(Path::new("test/first.rs")),
},
Some(PathBuf::from("/src/test/first.rs"))
Some(PathBuf::from(path!("/src/test/first.rs")))
)],
"Should show 1st opened item in the history when opening the 2nd item"
);
@ -663,14 +664,14 @@ async fn test_query_history(cx: &mut gpui::TestAppContext) {
worktree_id,
path: Arc::from(Path::new("test/second.rs")),
},
Some(PathBuf::from("/src/test/second.rs"))
Some(PathBuf::from(path!("/src/test/second.rs")))
),
FoundPath::new(
ProjectPath {
worktree_id,
path: Arc::from(Path::new("test/first.rs")),
},
Some(PathBuf::from("/src/test/first.rs"))
Some(PathBuf::from(path!("/src/test/first.rs")))
),
],
"Should show 1st and 2nd opened items in the history when opening the 3rd item. \
@ -687,21 +688,21 @@ async fn test_query_history(cx: &mut gpui::TestAppContext) {
worktree_id,
path: Arc::from(Path::new("test/third.rs")),
},
Some(PathBuf::from("/src/test/third.rs"))
Some(PathBuf::from(path!("/src/test/third.rs")))
),
FoundPath::new(
ProjectPath {
worktree_id,
path: Arc::from(Path::new("test/second.rs")),
},
Some(PathBuf::from("/src/test/second.rs"))
Some(PathBuf::from(path!("/src/test/second.rs")))
),
FoundPath::new(
ProjectPath {
worktree_id,
path: Arc::from(Path::new("test/first.rs")),
},
Some(PathBuf::from("/src/test/first.rs"))
Some(PathBuf::from(path!("/src/test/first.rs")))
),
],
"Should show 1st, 2nd and 3rd opened items in the history when opening the 2nd item again. \
@ -718,21 +719,21 @@ async fn test_query_history(cx: &mut gpui::TestAppContext) {
worktree_id,
path: Arc::from(Path::new("test/second.rs")),
},
Some(PathBuf::from("/src/test/second.rs"))
Some(PathBuf::from(path!("/src/test/second.rs")))
),
FoundPath::new(
ProjectPath {
worktree_id,
path: Arc::from(Path::new("test/third.rs")),
},
Some(PathBuf::from("/src/test/third.rs"))
Some(PathBuf::from(path!("/src/test/third.rs")))
),
FoundPath::new(
ProjectPath {
worktree_id,
path: Arc::from(Path::new("test/first.rs")),
},
Some(PathBuf::from("/src/test/first.rs"))
Some(PathBuf::from(path!("/src/test/first.rs")))
),
],
"Should show 1st, 2nd and 3rd opened items in the history when opening the 3rd item again. \
@ -748,7 +749,7 @@ async fn test_external_files_history(cx: &mut gpui::TestAppContext) {
.fs
.as_fake()
.insert_tree(
"/src",
path!("/src"),
json!({
"test": {
"first.rs": "// First Rust file",
@ -762,7 +763,7 @@ async fn test_external_files_history(cx: &mut gpui::TestAppContext) {
.fs
.as_fake()
.insert_tree(
"/external-src",
path!("/external-src"),
json!({
"test": {
"third.rs": "// Third Rust file",
@ -772,10 +773,10 @@ async fn test_external_files_history(cx: &mut gpui::TestAppContext) {
)
.await;
let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;
let project = Project::test(app_state.fs.clone(), [path!("/src").as_ref()], cx).await;
cx.update(|cx| {
project.update(cx, |project, cx| {
project.find_or_create_worktree("/external-src", false, cx)
project.find_or_create_worktree(path!("/external-src"), false, cx)
})
})
.detach();
@ -791,7 +792,7 @@ async fn test_external_files_history(cx: &mut gpui::TestAppContext) {
workspace
.update_in(cx, |workspace, window, cx| {
workspace.open_abs_path(
PathBuf::from("/external-src/test/third.rs"),
PathBuf::from(path!("/external-src/test/third.rs")),
false,
window,
cx,
@ -827,7 +828,7 @@ async fn test_external_files_history(cx: &mut gpui::TestAppContext) {
worktree_id: external_worktree_id,
path: Arc::from(Path::new("")),
},
Some(PathBuf::from("/external-src/test/third.rs"))
Some(PathBuf::from(path!("/external-src/test/third.rs")))
)],
"Should show external file with its full path in the history after it was open"
);
@ -842,14 +843,14 @@ async fn test_external_files_history(cx: &mut gpui::TestAppContext) {
worktree_id,
path: Arc::from(Path::new("test/second.rs")),
},
Some(PathBuf::from("/src/test/second.rs"))
Some(PathBuf::from(path!("/src/test/second.rs")))
),
FoundPath::new(
ProjectPath {
worktree_id: external_worktree_id,
path: Arc::from(Path::new("")),
},
Some(PathBuf::from("/external-src/test/third.rs"))
Some(PathBuf::from(path!("/external-src/test/third.rs")))
),
],
"Should keep external file with history updates",
@ -864,7 +865,7 @@ async fn test_toggle_panel_new_selections(cx: &mut gpui::TestAppContext) {
.fs
.as_fake()
.insert_tree(
"/src",
path!("/src"),
json!({
"test": {
"first.rs": "// First Rust file",
@ -875,7 +876,7 @@ async fn test_toggle_panel_new_selections(cx: &mut gpui::TestAppContext) {
)
.await;
let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;
let project = Project::test(app_state.fs.clone(), [path!("/src").as_ref()], cx).await;
let (workspace, cx) = cx.add_window_view(|window, cx| Workspace::test_new(project, window, cx));
// generate some history to select from
@ -919,7 +920,7 @@ async fn test_search_preserves_history_items(cx: &mut gpui::TestAppContext) {
.fs
.as_fake()
.insert_tree(
"/src",
path!("/src"),
json!({
"test": {
"first.rs": "// First Rust file",
@ -931,7 +932,7 @@ async fn test_search_preserves_history_items(cx: &mut gpui::TestAppContext) {
)
.await;
let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;
let project = Project::test(app_state.fs.clone(), [path!("/src").as_ref()], cx).await;
let (workspace, cx) = cx.add_window_view(|window, cx| Workspace::test_new(project, window, cx));
let worktree_id = cx.read(|cx| {
let worktrees = workspace.read(cx).worktrees(cx).collect::<Vec<_>>();
@ -964,7 +965,7 @@ async fn test_search_preserves_history_items(cx: &mut gpui::TestAppContext) {
worktree_id,
path: Arc::from(Path::new("test/first.rs")),
},
Some(PathBuf::from("/src/test/first.rs"))
Some(PathBuf::from(path!("/src/test/first.rs")))
));
assert_eq!(matches.search.len(), 1, "Only one non-history item contains {first_query}, it should be present");
assert_eq!(matches.search.first().unwrap(), Path::new("test/fourth.rs"));
@ -1007,7 +1008,7 @@ async fn test_search_preserves_history_items(cx: &mut gpui::TestAppContext) {
worktree_id,
path: Arc::from(Path::new("test/first.rs")),
},
Some(PathBuf::from("/src/test/first.rs"))
Some(PathBuf::from(path!("/src/test/first.rs")))
));
assert_eq!(matches.search.len(), 1, "Only one non-history item contains {first_query_again}, it should be present, even after non-matching query");
assert_eq!(matches.search.first().unwrap(), Path::new("test/fourth.rs"));
@ -1022,7 +1023,7 @@ async fn test_search_sorts_history_items(cx: &mut gpui::TestAppContext) {
.fs
.as_fake()
.insert_tree(
"/root",
path!("/root"),
json!({
"test": {
"1_qw": "// First file that matches the query",
@ -1037,7 +1038,7 @@ async fn test_search_sorts_history_items(cx: &mut gpui::TestAppContext) {
)
.await;
let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;
let project = Project::test(app_state.fs.clone(), [path!("/root").as_ref()], cx).await;
let (workspace, cx) = cx.add_window_view(|window, cx| Workspace::test_new(project, window, cx));
// generate some history to select from
open_close_queried_buffer("1", 1, "1_qw", &workspace, cx).await;
@ -1079,7 +1080,7 @@ async fn test_select_current_open_file_when_no_history(cx: &mut gpui::TestAppCon
.fs
.as_fake()
.insert_tree(
"/root",
path!("/root"),
json!({
"test": {
"1_qw": "",
@ -1088,7 +1089,7 @@ async fn test_select_current_open_file_when_no_history(cx: &mut gpui::TestAppCon
)
.await;
let project = Project::test(app_state.fs.clone(), ["/root".as_ref()], cx).await;
let project = Project::test(app_state.fs.clone(), [path!("/root").as_ref()], cx).await;
let (workspace, cx) = cx.add_window_view(|window, cx| Workspace::test_new(project, window, cx));
// Open new buffer
open_queried_buffer("1", 1, "1_qw", &workspace, cx).await;
@ -1109,7 +1110,7 @@ async fn test_keep_opened_file_on_top_of_search_results_and_select_next_one(
.fs
.as_fake()
.insert_tree(
"/src",
path!("/src"),
json!({
"test": {
"bar.rs": "// Bar file",
@ -1122,7 +1123,7 @@ async fn test_keep_opened_file_on_top_of_search_results_and_select_next_one(
)
.await;
let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;
let project = Project::test(app_state.fs.clone(), [path!("/src").as_ref()], cx).await;
let (workspace, cx) = cx.add_window_view(|window, cx| Workspace::test_new(project, window, cx));
open_close_queried_buffer("bar", 1, "bar.rs", &workspace, cx).await;
@ -1202,7 +1203,7 @@ async fn test_non_separate_history_items(cx: &mut TestAppContext) {
.fs
.as_fake()
.insert_tree(
"/src",
path!("/src"),
json!({
"test": {
"bar.rs": "// Bar file",
@ -1215,7 +1216,7 @@ async fn test_non_separate_history_items(cx: &mut TestAppContext) {
)
.await;
let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;
let project = Project::test(app_state.fs.clone(), [path!("/src").as_ref()], cx).await;
let (workspace, cx) = cx.add_window_view(|window, cx| Workspace::test_new(project, window, cx));
open_close_queried_buffer("bar", 1, "bar.rs", &workspace, cx).await;
@ -1296,7 +1297,7 @@ async fn test_history_items_shown_in_order_of_open(cx: &mut TestAppContext) {
.fs
.as_fake()
.insert_tree(
"/test",
path!("/test"),
json!({
"test": {
"1.txt": "// One",
@ -1307,7 +1308,7 @@ async fn test_history_items_shown_in_order_of_open(cx: &mut TestAppContext) {
)
.await;
let project = Project::test(app_state.fs.clone(), ["/test".as_ref()], cx).await;
let project = Project::test(app_state.fs.clone(), [path!("/test").as_ref()], cx).await;
let (workspace, cx) = cx.add_window_view(|window, cx| Workspace::test_new(project, window, cx));
open_queried_buffer("1", 1, "1.txt", &workspace, cx).await;
@ -1354,7 +1355,7 @@ async fn test_selected_history_item_stays_selected_on_worktree_updated(cx: &mut
.fs
.as_fake()
.insert_tree(
"/test",
path!("/test"),
json!({
"test": {
"1.txt": "// One",
@ -1365,7 +1366,7 @@ async fn test_selected_history_item_stays_selected_on_worktree_updated(cx: &mut
)
.await;
let project = Project::test(app_state.fs.clone(), ["/test".as_ref()], cx).await;
let project = Project::test(app_state.fs.clone(), [path!("/test").as_ref()], cx).await;
let (workspace, cx) = cx.add_window_view(|window, cx| Workspace::test_new(project, window, cx));
open_close_queried_buffer("1", 1, "1.txt", &workspace, cx).await;
@ -1384,7 +1385,11 @@ async fn test_selected_history_item_stays_selected_on_worktree_updated(cx: &mut
// Add more files to the worktree to trigger update matches
for i in 0..5 {
let filename = format!("/test/{}.txt", 4 + i);
let filename = if cfg!(windows) {
format!("C:/test/{}.txt", 4 + i)
} else {
format!("/test/{}.txt", 4 + i)
};
app_state
.fs
.create_file(Path::new(&filename), Default::default())
@ -1410,7 +1415,7 @@ async fn test_history_items_vs_very_good_external_match(cx: &mut gpui::TestAppCo
.fs
.as_fake()
.insert_tree(
"/src",
path!("/src"),
json!({
"collab_ui": {
"first.rs": "// First Rust file",
@ -1422,7 +1427,7 @@ async fn test_history_items_vs_very_good_external_match(cx: &mut gpui::TestAppCo
)
.await;
let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;
let project = Project::test(app_state.fs.clone(), [path!("/src").as_ref()], cx).await;
let (workspace, cx) = cx.add_window_view(|window, cx| Workspace::test_new(project, window, cx));
// generate some history to select from
open_close_queried_buffer("fir", 1, "first.rs", &workspace, cx).await;
@ -1456,7 +1461,7 @@ async fn test_nonexistent_history_items_not_shown(cx: &mut gpui::TestAppContext)
.fs
.as_fake()
.insert_tree(
"/src",
path!("/src"),
json!({
"test": {
"first.rs": "// First Rust file",
@ -1467,7 +1472,7 @@ async fn test_nonexistent_history_items_not_shown(cx: &mut gpui::TestAppContext)
)
.await;
let project = Project::test(app_state.fs.clone(), ["/src".as_ref()], cx).await;
let project = Project::test(app_state.fs.clone(), [path!("/src").as_ref()], cx).await;
let (workspace, cx) = cx.add_window_view(|window, cx| Workspace::test_new(project, window, cx)); // generate some history to select from
open_close_queried_buffer("fir", 1, "first.rs", &workspace, cx).await;
open_close_queried_buffer("non", 1, "nonexistent.rs", &workspace, cx).await;
@ -1476,7 +1481,7 @@ async fn test_nonexistent_history_items_not_shown(cx: &mut gpui::TestAppContext)
app_state
.fs
.remove_file(
Path::new("/src/test/nonexistent.rs"),
Path::new(path!("/src/test/nonexistent.rs")),
RemoveOptions::default(),
)
.await
@ -1742,14 +1747,14 @@ async fn test_keeps_file_finder_open_after_modifier_keys_release(cx: &mut gpui::
.fs
.as_fake()
.insert_tree(
"/test",
path!("/test"),
json!({
"1.txt": "// One",
}),
)
.await;
let project = Project::test(app_state.fs.clone(), ["/test".as_ref()], cx).await;
let project = Project::test(app_state.fs.clone(), [path!("/test").as_ref()], cx).await;
let (workspace, cx) = cx.add_window_view(|window, cx| Workspace::test_new(project, window, cx));
open_queried_buffer("1", 1, "1.txt", &workspace, cx).await;
@ -1809,7 +1814,7 @@ async fn test_switches_between_release_norelease_modes_on_forward_nav(
.fs
.as_fake()
.insert_tree(
"/test",
path!("/test"),
json!({
"1.txt": "// One",
"2.txt": "// Two",
@ -1817,7 +1822,7 @@ async fn test_switches_between_release_norelease_modes_on_forward_nav(
)
.await;
let project = Project::test(app_state.fs.clone(), ["/test".as_ref()], cx).await;
let project = Project::test(app_state.fs.clone(), [path!("/test").as_ref()], cx).await;
let (workspace, cx) = cx.add_window_view(|window, cx| Workspace::test_new(project, window, cx));
open_queried_buffer("1", 1, "1.txt", &workspace, cx).await;
@ -1864,7 +1869,7 @@ async fn test_switches_between_release_norelease_modes_on_backward_nav(
.fs
.as_fake()
.insert_tree(
"/test",
path!("/test"),
json!({
"1.txt": "// One",
"2.txt": "// Two",
@ -1873,7 +1878,7 @@ async fn test_switches_between_release_norelease_modes_on_backward_nav(
)
.await;
let project = Project::test(app_state.fs.clone(), ["/test".as_ref()], cx).await;
let project = Project::test(app_state.fs.clone(), [path!("/test").as_ref()], cx).await;
let (workspace, cx) = cx.add_window_view(|window, cx| Workspace::test_new(project, window, cx));
open_queried_buffer("1", 1, "1.txt", &workspace, cx).await;
@ -1921,14 +1926,14 @@ async fn test_extending_modifiers_does_not_confirm_selection(cx: &mut gpui::Test
.fs
.as_fake()
.insert_tree(
"/test",
path!("/test"),
json!({
"1.txt": "// One",
}),
)
.await;
let project = Project::test(app_state.fs.clone(), ["/test".as_ref()], cx).await;
let project = Project::test(app_state.fs.clone(), [path!("/test").as_ref()], cx).await;
let (workspace, cx) = cx.add_window_view(|window, cx| Workspace::test_new(project, window, cx));
open_queried_buffer("1", 1, "1.txt", &workspace, cx).await;