Skip to content

Commit 5506669

Browse files
windows: Fix more windows platform test (#19802)
Release Notes: - N/A --------- Co-authored-by: Kirill Bulatov <kirill@zed.dev>
1 parent b139407 commit 5506669

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

crates/editor/src/test/editor_test_context.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use project::{FakeFs, Project};
1717
use std::{
1818
any::TypeId,
1919
ops::{Deref, DerefMut, Range},
20+
path::Path,
2021
sync::{
2122
atomic::{AtomicUsize, Ordering},
2223
Arc,
@@ -42,17 +43,18 @@ impl EditorTestContext {
4243
pub async fn new(cx: &mut gpui::TestAppContext) -> EditorTestContext {
4344
let fs = FakeFs::new(cx.executor());
4445
// fs.insert_file("/file", "".to_owned()).await;
46+
let root = Self::root_path();
4547
fs.insert_tree(
46-
"/root",
48+
root,
4749
serde_json::json!({
4850
"file": "",
4951
}),
5052
)
5153
.await;
52-
let project = Project::test(fs, ["/root".as_ref()], cx).await;
54+
let project = Project::test(fs, [root], cx).await;
5355
let buffer = project
5456
.update(cx, |project, cx| {
55-
project.open_local_buffer("/root/file", cx)
57+
project.open_local_buffer(root.join("file"), cx)
5658
})
5759
.await
5860
.unwrap();
@@ -71,6 +73,16 @@ impl EditorTestContext {
7173
}
7274
}
7375

76+
#[cfg(target_os = "windows")]
77+
fn root_path() -> &'static Path {
78+
Path::new("C:\\root")
79+
}
80+
81+
#[cfg(not(target_os = "windows"))]
82+
fn root_path() -> &'static Path {
83+
Path::new("/root")
84+
}
85+
7486
pub async fn for_editor(editor: WindowHandle<Editor>, cx: &mut gpui::TestAppContext) -> Self {
7587
let editor_view = editor.root_view(cx).unwrap();
7688
Self {

crates/fs/src/fs.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -875,9 +875,11 @@ impl FakeFsState {
875875
canonical_path.clear();
876876
match prefix {
877877
Some(prefix_component) => {
878-
canonical_path.push(prefix_component.as_os_str());
878+
canonical_path = PathBuf::from(prefix_component.as_os_str());
879+
// Prefixes like `C:\\` are represented without their trailing slash, so we have to re-add it.
880+
canonical_path.push(std::path::MAIN_SEPARATOR_STR);
879881
}
880-
None => canonical_path.push("/"),
882+
None => canonical_path = PathBuf::from(std::path::MAIN_SEPARATOR_STR),
881883
}
882884
}
883885
Component::CurDir => {}
@@ -900,7 +902,7 @@ impl FakeFsState {
900902
}
901903
}
902904
entry_stack.push(entry.clone());
903-
canonical_path.push(name);
905+
canonical_path = canonical_path.join(name);
904906
} else {
905907
return None;
906908
}
@@ -962,6 +964,10 @@ pub static FS_DOT_GIT: std::sync::LazyLock<&'static OsStr> =
962964

963965
#[cfg(any(test, feature = "test-support"))]
964966
impl FakeFs {
967+
/// We need to use something large enough for Windows and Unix to consider this a new file.
968+
/// https://doc.rust-lang.org/nightly/std/time/struct.SystemTime.html#platform-specific-behavior
969+
const SYSTEMTIME_INTERVAL: u64 = 100;
970+
965971
pub fn new(executor: gpui::BackgroundExecutor) -> Arc<Self> {
966972
Arc::new(Self {
967973
executor,
@@ -995,7 +1001,7 @@ impl FakeFs {
9951001
let new_mtime = state.next_mtime;
9961002
let new_inode = state.next_inode;
9971003
state.next_inode += 1;
998-
state.next_mtime += Duration::from_nanos(1);
1004+
state.next_mtime += Duration::from_nanos(Self::SYSTEMTIME_INTERVAL);
9991005
state
10001006
.write_path(path, move |entry| {
10011007
match entry {
@@ -1048,7 +1054,7 @@ impl FakeFs {
10481054
let inode = state.next_inode;
10491055
let mtime = state.next_mtime;
10501056
state.next_inode += 1;
1051-
state.next_mtime += Duration::from_nanos(1);
1057+
state.next_mtime += Duration::from_nanos(Self::SYSTEMTIME_INTERVAL);
10521058
let file = Arc::new(Mutex::new(FakeFsEntry::File {
10531059
inode,
10541060
mtime,
@@ -1399,7 +1405,7 @@ impl Fs for FakeFs {
13991405

14001406
let inode = state.next_inode;
14011407
let mtime = state.next_mtime;
1402-
state.next_mtime += Duration::from_nanos(1);
1408+
state.next_mtime += Duration::from_nanos(Self::SYSTEMTIME_INTERVAL);
14031409
state.next_inode += 1;
14041410
state.write_path(&cur_path, |entry| {
14051411
entry.or_insert_with(|| {
@@ -1425,7 +1431,7 @@ impl Fs for FakeFs {
14251431
let mut state = self.state.lock();
14261432
let inode = state.next_inode;
14271433
let mtime = state.next_mtime;
1428-
state.next_mtime += Duration::from_nanos(1);
1434+
state.next_mtime += Duration::from_nanos(Self::SYSTEMTIME_INTERVAL);
14291435
state.next_inode += 1;
14301436
let file = Arc::new(Mutex::new(FakeFsEntry::File {
14311437
inode,
@@ -1560,7 +1566,7 @@ impl Fs for FakeFs {
15601566
let mut state = self.state.lock();
15611567
let mtime = state.next_mtime;
15621568
let inode = util::post_inc(&mut state.next_inode);
1563-
state.next_mtime += Duration::from_nanos(1);
1569+
state.next_mtime += Duration::from_nanos(Self::SYSTEMTIME_INTERVAL);
15641570
let source_entry = state.read_path(&source)?;
15651571
let content = source_entry.lock().file_content(&source)?.clone();
15661572
let mut kind = Some(PathEventKind::Created);

0 commit comments

Comments
 (0)