Fix a few Windows tests (#19773)

This commit is contained in:
Kirill Bulatov 2024-10-26 03:32:22 +03:00 committed by GitHub
parent fc8a72cdd8
commit d7a277607b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 43 additions and 11 deletions

View file

@ -1,6 +1,7 @@
use std::{ use std::{
borrow::Cow, borrow::Cow,
ops::{Deref, DerefMut, Range}, ops::{Deref, DerefMut, Range},
path::Path,
sync::Arc, sync::Arc,
}; };
@ -66,10 +67,12 @@ impl EditorLspTestContext {
); );
language_registry.add(Arc::new(language)); language_registry.add(Arc::new(language));
let root = Self::root_path();
app_state app_state
.fs .fs
.as_fake() .as_fake()
.insert_tree("/root", json!({ "dir": { file_name.clone(): "" }})) .insert_tree(root, json!({ "dir": { file_name.clone(): "" }}))
.await; .await;
let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx)); let window = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
@ -79,7 +82,7 @@ impl EditorLspTestContext {
let mut cx = VisualTestContext::from_window(*window.deref(), cx); let mut cx = VisualTestContext::from_window(*window.deref(), cx);
project project
.update(&mut cx, |project, cx| { .update(&mut cx, |project, cx| {
project.find_or_create_worktree("/root", true, cx) project.find_or_create_worktree(root, true, cx)
}) })
.await .await
.unwrap(); .unwrap();
@ -108,7 +111,7 @@ impl EditorLspTestContext {
}, },
lsp, lsp,
workspace, workspace,
buffer_lsp_url: lsp::Url::from_file_path(format!("/root/dir/{file_name}")).unwrap(), buffer_lsp_url: lsp::Url::from_file_path(root.join("dir").join(file_name)).unwrap(),
} }
} }
@ -310,6 +313,16 @@ impl EditorLspTestContext {
pub fn notify<T: notification::Notification>(&self, params: T::Params) { pub fn notify<T: notification::Notification>(&self, params: T::Params) {
self.lsp.notify::<T>(params); self.lsp.notify::<T>(params);
} }
#[cfg(target_os = "windows")]
fn root_path() -> &'static Path {
Path::new("C:\\root")
}
#[cfg(not(target_os = "windows"))]
fn root_path() -> &'static Path {
Path::new("/root")
}
} }
impl Deref for EditorLspTestContext { impl Deref for EditorLspTestContext {

View file

@ -865,14 +865,20 @@ impl FakeFsState {
let mut entry_stack = Vec::new(); let mut entry_stack = Vec::new();
'outer: loop { 'outer: loop {
let mut path_components = path.components().peekable(); let mut path_components = path.components().peekable();
let mut prefix = None;
while let Some(component) = path_components.next() { while let Some(component) = path_components.next() {
match component { match component {
Component::Prefix(_) => panic!("prefix paths aren't supported"), Component::Prefix(prefix_component) => prefix = Some(prefix_component),
Component::RootDir => { Component::RootDir => {
entry_stack.clear(); entry_stack.clear();
entry_stack.push(self.root.clone()); entry_stack.push(self.root.clone());
canonical_path.clear(); canonical_path.clear();
canonical_path.push("/"); match prefix {
Some(prefix_component) => {
canonical_path.push(prefix_component.as_os_str());
}
None => canonical_path.push("/"),
}
} }
Component::CurDir => {} Component::CurDir => {}
Component::ParentDir => { Component::ParentDir => {
@ -1384,11 +1390,12 @@ impl Fs for FakeFs {
let mut created_dirs = Vec::new(); let mut created_dirs = Vec::new();
let mut cur_path = PathBuf::new(); let mut cur_path = PathBuf::new();
for component in path.components() { for component in path.components() {
let mut state = self.state.lock(); let should_skip = matches!(component, Component::Prefix(..) | Component::RootDir);
cur_path.push(component); cur_path.push(component);
if cur_path == Path::new("/") { if should_skip {
continue; continue;
} }
let mut state = self.state.lock();
let inode = state.next_inode; let inode = state.next_inode;
let mtime = state.next_mtime; let mtime = state.next_mtime;

View file

@ -1177,6 +1177,8 @@ impl FakeLanguageServer {
let (stdout_writer, stdout_reader) = async_pipe::pipe(); let (stdout_writer, stdout_reader) = async_pipe::pipe();
let (notifications_tx, notifications_rx) = channel::unbounded(); let (notifications_tx, notifications_rx) = channel::unbounded();
let root = Self::root_path();
let mut server = LanguageServer::new_internal( let mut server = LanguageServer::new_internal(
server_id, server_id,
stdin_writer, stdin_writer,
@ -1184,8 +1186,8 @@ impl FakeLanguageServer {
None::<async_pipe::PipeReader>, None::<async_pipe::PipeReader>,
Arc::new(Mutex::new(None)), Arc::new(Mutex::new(None)),
None, None,
Path::new("/"), root,
Path::new("/"), root,
None, None,
cx.clone(), cx.clone(),
|_| {}, |_| {},
@ -1201,8 +1203,8 @@ impl FakeLanguageServer {
None::<async_pipe::PipeReader>, None::<async_pipe::PipeReader>,
Arc::new(Mutex::new(None)), Arc::new(Mutex::new(None)),
None, None,
Path::new("/"), root,
Path::new("/"), root,
None, None,
cx, cx,
move |msg| { move |msg| {
@ -1238,6 +1240,16 @@ impl FakeLanguageServer {
(server, fake) (server, fake)
} }
#[cfg(target_os = "windows")]
fn root_path() -> &'static Path {
Path::new("C:\\")
}
#[cfg(not(target_os = "windows"))]
fn root_path() -> &'static Path {
Path::new("/")
}
} }
#[cfg(any(test, feature = "test-support"))] #[cfg(any(test, feature = "test-support"))]