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

@ -1569,6 +1569,7 @@ mod tests {
time::Duration,
};
use theme::{ThemeRegistry, ThemeSettings};
use util::{path, separator};
use workspace::{
item::{Item, ItemHandle},
open_new, open_paths, pane, NewFile, OpenVisible, SaveIntent, SplitDirection,
@ -1737,12 +1738,15 @@ mod tests {
app_state
.fs
.as_fake()
.insert_tree("/root", json!({"a": "hey", "b": "", "dir": {"c": "f"}}))
.insert_tree(
path!("/root"),
json!({"a": "hey", "b": "", "dir": {"c": "f"}}),
)
.await;
cx.update(|cx| {
open_paths(
&[PathBuf::from("/root/dir")],
&[PathBuf::from(path!("/root/dir"))],
app_state.clone(),
workspace::OpenOptions::default(),
cx,
@ -1754,7 +1758,7 @@ mod tests {
cx.update(|cx| {
open_paths(
&[PathBuf::from("/root/a")],
&[PathBuf::from(path!("/root/a"))],
app_state.clone(),
workspace::OpenOptions {
open_new_workspace: Some(false),
@ -1769,7 +1773,7 @@ mod tests {
cx.update(|cx| {
open_paths(
&[PathBuf::from("/root/dir/c")],
&[PathBuf::from(path!("/root/dir/c"))],
app_state.clone(),
workspace::OpenOptions {
open_new_workspace: Some(true),
@ -1789,12 +1793,15 @@ mod tests {
app_state
.fs
.as_fake()
.insert_tree("/root", json!({"dir1": {"a": "b"}, "dir2": {"c": "d"}}))
.insert_tree(
path!("/root"),
json!({"dir1": {"a": "b"}, "dir2": {"c": "d"}}),
)
.await;
cx.update(|cx| {
open_paths(
&[PathBuf::from("/root/dir1/a")],
&[PathBuf::from(path!("/root/dir1/a"))],
app_state.clone(),
workspace::OpenOptions::default(),
cx,
@ -1807,7 +1814,7 @@ mod tests {
cx.update(|cx| {
open_paths(
&[PathBuf::from("/root/dir2/c")],
&[PathBuf::from(path!("/root/dir2/c"))],
app_state.clone(),
workspace::OpenOptions::default(),
cx,
@ -1819,7 +1826,7 @@ mod tests {
cx.update(|cx| {
open_paths(
&[PathBuf::from("/root/dir2")],
&[PathBuf::from(path!("/root/dir2"))],
app_state.clone(),
workspace::OpenOptions::default(),
cx,
@ -1835,7 +1842,7 @@ mod tests {
cx.update(|cx| {
open_paths(
&[PathBuf::from("/root/dir2/c")],
&[PathBuf::from(path!("/root/dir2/c"))],
app_state.clone(),
workspace::OpenOptions::default(),
cx,
@ -1864,12 +1871,12 @@ mod tests {
app_state
.fs
.as_fake()
.insert_tree("/root", json!({"a": "hey"}))
.insert_tree(path!("/root"), json!({"a": "hey"}))
.await;
cx.update(|cx| {
open_paths(
&[PathBuf::from("/root/a")],
&[PathBuf::from(path!("/root/a"))],
app_state.clone(),
workspace::OpenOptions::default(),
cx,
@ -1951,7 +1958,7 @@ mod tests {
// Opening the buffer again doesn't impact the window's edited state.
cx.update(|cx| {
open_paths(
&[PathBuf::from("/root/a")],
&[PathBuf::from(path!("/root/a"))],
app_state,
workspace::OpenOptions::default(),
cx,
@ -2013,12 +2020,12 @@ mod tests {
app_state
.fs
.as_fake()
.insert_tree("/root", json!({"a": "hey"}))
.insert_tree(path!("/root"), json!({"a": "hey"}))
.await;
cx.update(|cx| {
open_paths(
&[PathBuf::from("/root/a")],
&[PathBuf::from(path!("/root/a"))],
app_state.clone(),
workspace::OpenOptions::default(),
cx,
@ -2070,7 +2077,7 @@ mod tests {
// When we now reopen the window, the edited state and the edited buffer are back
cx.update(|cx| {
open_paths(
&[PathBuf::from("/root/a")],
&[PathBuf::from(path!("/root/a"))],
app_state.clone(),
workspace::OpenOptions::default(),
cx,
@ -2166,7 +2173,7 @@ mod tests {
.fs
.as_fake()
.insert_tree(
"/root",
path!("/root"),
json!({
"a": {
"file1": "contents 1",
@ -2177,7 +2184,7 @@ mod tests {
)
.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;
project.update(cx, |project, _cx| {
project.languages().add(markdown_language())
});
@ -2298,7 +2305,7 @@ mod tests {
.fs
.as_fake()
.insert_tree(
"/",
path!("/"),
json!({
"dir1": {
"a.txt": ""
@ -2316,7 +2323,7 @@ mod tests {
cx.update(|cx| {
open_paths(
&[PathBuf::from("/dir1/")],
&[PathBuf::from(path!("/dir1/"))],
app_state,
workspace::OpenOptions::default(),
cx,
@ -2363,7 +2370,7 @@ mod tests {
window
.update(cx, |workspace, window, cx| {
workspace.open_paths(
vec!["/dir1/a.txt".into()],
vec![path!("/dir1/a.txt").into()],
OpenVisible::All,
None,
window,
@ -2374,7 +2381,12 @@ mod tests {
.await;
cx.read(|cx| {
let workspace = workspace.read(cx);
assert_project_panel_selection(workspace, Path::new("/dir1"), Path::new("a.txt"), cx);
assert_project_panel_selection(
workspace,
Path::new(path!("/dir1")),
Path::new("a.txt"),
cx,
);
assert_eq!(
workspace
.active_pane()
@ -2393,7 +2405,7 @@ mod tests {
window
.update(cx, |workspace, window, cx| {
workspace.open_paths(
vec!["/dir2/b.txt".into()],
vec![path!("/dir2/b.txt").into()],
OpenVisible::All,
None,
window,
@ -2404,14 +2416,19 @@ mod tests {
.await;
cx.read(|cx| {
let workspace = workspace.read(cx);
assert_project_panel_selection(workspace, Path::new("/dir2/b.txt"), Path::new(""), cx);
assert_project_panel_selection(
workspace,
Path::new(path!("/dir2/b.txt")),
Path::new(""),
cx,
);
let worktree_roots = workspace
.worktrees(cx)
.map(|w| w.read(cx).as_local().unwrap().abs_path().as_ref())
.collect::<HashSet<_>>();
assert_eq!(
worktree_roots,
vec!["/dir1", "/dir2/b.txt"]
vec![path!("/dir1"), path!("/dir2/b.txt")]
.into_iter()
.map(Path::new)
.collect(),
@ -2434,7 +2451,7 @@ mod tests {
window
.update(cx, |workspace, window, cx| {
workspace.open_paths(
vec!["/dir3".into(), "/dir3/c.txt".into()],
vec![path!("/dir3").into(), path!("/dir3/c.txt").into()],
OpenVisible::All,
None,
window,
@ -2445,14 +2462,19 @@ mod tests {
.await;
cx.read(|cx| {
let workspace = workspace.read(cx);
assert_project_panel_selection(workspace, Path::new("/dir3"), Path::new("c.txt"), cx);
assert_project_panel_selection(
workspace,
Path::new(path!("/dir3")),
Path::new("c.txt"),
cx,
);
let worktree_roots = workspace
.worktrees(cx)
.map(|w| w.read(cx).as_local().unwrap().abs_path().as_ref())
.collect::<HashSet<_>>();
assert_eq!(
worktree_roots,
vec!["/dir1", "/dir2/b.txt", "/dir3"]
vec![path!("/dir1"), path!("/dir2/b.txt"), path!("/dir3")]
.into_iter()
.map(Path::new)
.collect(),
@ -2474,23 +2496,39 @@ mod tests {
// Ensure opening invisibly a file outside an existing worktree adds a new, invisible worktree.
window
.update(cx, |workspace, window, cx| {
workspace.open_paths(vec!["/d.txt".into()], OpenVisible::None, None, window, cx)
workspace.open_paths(
vec![path!("/d.txt").into()],
OpenVisible::None,
None,
window,
cx,
)
})
.unwrap()
.await;
cx.read(|cx| {
let workspace = workspace.read(cx);
assert_project_panel_selection(workspace, Path::new("/d.txt"), Path::new(""), cx);
assert_project_panel_selection(
workspace,
Path::new(path!("/d.txt")),
Path::new(""),
cx,
);
let worktree_roots = workspace
.worktrees(cx)
.map(|w| w.read(cx).as_local().unwrap().abs_path().as_ref())
.collect::<HashSet<_>>();
assert_eq!(
worktree_roots,
vec!["/dir1", "/dir2/b.txt", "/dir3", "/d.txt"]
.into_iter()
.map(Path::new)
.collect(),
vec![
path!("/dir1"),
path!("/dir2/b.txt"),
path!("/dir3"),
path!("/d.txt")
]
.into_iter()
.map(Path::new)
.collect(),
);
let visible_worktree_roots = workspace
@ -2499,7 +2537,7 @@ mod tests {
.collect::<HashSet<_>>();
assert_eq!(
visible_worktree_roots,
vec!["/dir1", "/dir2/b.txt", "/dir3"]
vec![path!("/dir1"), path!("/dir2/b.txt"), path!("/dir3")]
.into_iter()
.map(Path::new)
.collect(),
@ -2535,7 +2573,7 @@ mod tests {
.fs
.as_fake()
.insert_tree(
"/root",
path!("/root"),
json!({
".gitignore": "ignored_dir\n",
".git": {
@ -2560,7 +2598,7 @@ mod tests {
)
.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;
project.update(cx, |project, _cx| {
project.languages().add(markdown_language())
});
@ -2569,9 +2607,9 @@ mod tests {
let initial_entries = cx.read(|cx| workspace.file_project_paths(cx));
let paths_to_open = [
Path::new("/root/excluded_dir/file").to_path_buf(),
Path::new("/root/.git/HEAD").to_path_buf(),
Path::new("/root/excluded_dir/ignored_subdir").to_path_buf(),
PathBuf::from(path!("/root/excluded_dir/file")),
PathBuf::from(path!("/root/.git/HEAD")),
PathBuf::from(path!("/root/excluded_dir/ignored_subdir")),
];
let (opened_workspace, new_items) = cx
.update(|cx| {
@ -2616,8 +2654,8 @@ mod tests {
opened_paths,
vec![
None,
Some(".git/HEAD".to_string()),
Some("excluded_dir/file".to_string()),
Some(separator!(".git/HEAD").to_string()),
Some(separator!("excluded_dir/file").to_string()),
],
"Excluded files should get opened, excluded dir should not get opened"
);
@ -2643,7 +2681,7 @@ mod tests {
opened_buffer_paths.sort();
assert_eq!(
opened_buffer_paths,
vec![".git/HEAD".to_string(), "excluded_dir/file".to_string()],
vec![separator!(".git/HEAD").to_string(), separator!("excluded_dir/file").to_string()],
"Despite not being present in the worktrees, buffers for excluded files are opened and added to the pane"
);
});
@ -2655,10 +2693,10 @@ mod tests {
app_state
.fs
.as_fake()
.insert_tree("/root", json!({ "a.txt": "" }))
.insert_tree(path!("/root"), json!({ "a.txt": "" }))
.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;
project.update(cx, |project, _cx| {
project.languages().add(markdown_language())
});
@ -2669,7 +2707,7 @@ mod tests {
window
.update(cx, |workspace, window, cx| {
workspace.open_paths(
vec![PathBuf::from("/root/a.txt")],
vec![PathBuf::from(path!("/root/a.txt"))],
OpenVisible::All,
None,
window,
@ -2693,7 +2731,7 @@ mod tests {
app_state
.fs
.as_fake()
.insert_file("/root/a.txt", b"changed".to_vec())
.insert_file(path!("/root/a.txt"), b"changed".to_vec())
.await;
cx.run_until_parked();
@ -2721,9 +2759,13 @@ mod tests {
#[gpui::test]
async fn test_open_and_save_new_file(cx: &mut TestAppContext) {
let app_state = init_test(cx);
app_state.fs.create_dir(Path::new("/root")).await.unwrap();
app_state
.fs
.create_dir(Path::new(path!("/root")))
.await
.unwrap();
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;
project.update(cx, |project, _| {
project.languages().add(markdown_language());
project.languages().add(rust_lang());
@ -2766,7 +2808,7 @@ mod tests {
.unwrap();
cx.background_executor.run_until_parked();
cx.simulate_new_path_selection(|parent_dir| {
assert_eq!(parent_dir, Path::new("/root"));
assert_eq!(parent_dir, Path::new(path!("/root")));
Some(parent_dir.join("the-new-name.rs"))
});
cx.read(|cx| {
@ -2922,7 +2964,7 @@ mod tests {
.fs
.as_fake()
.insert_tree(
"/root",
path!("/root"),
json!({
"a": {
"file1": "contents 1",
@ -2933,7 +2975,7 @@ mod tests {
)
.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;
project.update(cx, |project, _cx| {
project.languages().add(markdown_language())
});
@ -3020,7 +3062,7 @@ mod tests {
.fs
.as_fake()
.insert_tree(
"/root",
path!("/root"),
json!({
"a": {
"file1": "contents 1\n".repeat(20),
@ -3031,7 +3073,7 @@ mod tests {
)
.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;
project.update(cx, |project, _cx| {
project.languages().add(markdown_language())
});
@ -3262,7 +3304,7 @@ mod tests {
.unwrap();
app_state
.fs
.remove_file(Path::new("/root/a/file2"), Default::default())
.remove_file(Path::new(path!("/root/a/file2")), Default::default())
.await
.unwrap();
cx.background_executor.run_until_parked();
@ -3403,7 +3445,7 @@ mod tests {
.fs
.as_fake()
.insert_tree(
"/root",
path!("/root"),
json!({
"a": {
"file1": "",
@ -3415,7 +3457,7 @@ mod tests {
)
.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;
project.update(cx, |project, _cx| {
project.languages().add(markdown_language())
});

View file

@ -535,6 +535,7 @@ mod tests {
use editor::Editor;
use gpui::TestAppContext;
use serde_json::json;
use util::path;
use workspace::{AppState, Workspace};
use crate::zed::{open_listener::open_local_workspace, tests::init_test};
@ -547,7 +548,7 @@ mod tests {
.fs
.as_fake()
.insert_tree(
"/root",
path!("/root"),
json!({
"dir1": {
"file1.txt": "content1",
@ -560,7 +561,7 @@ mod tests {
assert_eq!(cx.windows().len(), 0);
// First open the workspace directory
open_workspace_file("/root/dir1", None, app_state.clone(), cx).await;
open_workspace_file(path!("/root/dir1"), None, app_state.clone(), cx).await;
assert_eq!(cx.windows().len(), 1);
let workspace = cx.windows()[0].downcast::<Workspace>().unwrap();
@ -571,7 +572,7 @@ mod tests {
.unwrap();
// Now open a file inside that workspace
open_workspace_file("/root/dir1/file1.txt", None, app_state.clone(), cx).await;
open_workspace_file(path!("/root/dir1/file1.txt"), None, app_state.clone(), cx).await;
assert_eq!(cx.windows().len(), 1);
workspace
@ -581,7 +582,13 @@ mod tests {
.unwrap();
// Now open a file inside that workspace, but tell Zed to open a new window
open_workspace_file("/root/dir1/file1.txt", Some(true), app_state.clone(), cx).await;
open_workspace_file(
path!("/root/dir1/file1.txt"),
Some(true),
app_state.clone(),
cx,
)
.await;
assert_eq!(cx.windows().len(), 2);
@ -599,12 +606,16 @@ mod tests {
async fn test_open_workspace_with_nonexistent_files(cx: &mut TestAppContext) {
let app_state = init_test(cx);
app_state.fs.as_fake().insert_tree("/root", json!({})).await;
app_state
.fs
.as_fake()
.insert_tree(path!("/root"), json!({}))
.await;
assert_eq!(cx.windows().len(), 0);
// Test case 1: Open a single file that does not exist yet
open_workspace_file("/root/file5.txt", None, app_state.clone(), cx).await;
open_workspace_file(path!("/root/file5.txt"), None, app_state.clone(), cx).await;
assert_eq!(cx.windows().len(), 1);
let workspace_1 = cx.windows()[0].downcast::<Workspace>().unwrap();
@ -616,7 +627,7 @@ mod tests {
// Test case 2: Open a single file that does not exist yet,
// but tell Zed to add it to the current workspace
open_workspace_file("/root/file6.txt", Some(false), app_state.clone(), cx).await;
open_workspace_file(path!("/root/file6.txt"), Some(false), app_state.clone(), cx).await;
assert_eq!(cx.windows().len(), 1);
workspace_1
@ -628,7 +639,7 @@ mod tests {
// Test case 3: Open a single file that does not exist yet,
// but tell Zed to NOT add it to the current workspace
open_workspace_file("/root/file7.txt", Some(true), app_state.clone(), cx).await;
open_workspace_file(path!("/root/file7.txt"), Some(true), app_state.clone(), cx).await;
assert_eq!(cx.windows().len(), 2);
let workspace_2 = cx.windows()[1].downcast::<Workspace>().unwrap();