Canonicalize paths when running tests (#23655)

In the Windows test environment, the paths generated by `temp_tree()`
are symlink paths, which causes certain tests to fail.

I later noticed that when opening a project, we seem to always use
`canonicalize` to normalize the paths, as shown here:
https://github.com/zed-industries/zed/pull/21039.

This PR adopts a similar approach for the test environment to address
the issue.

Release Notes:

- N/A
This commit is contained in:
张小白 2025-01-26 14:56:07 +08:00 committed by GitHub
parent 0f8e2e3811
commit 5d005a7621
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 43 additions and 27 deletions

View file

@ -11,10 +11,26 @@ use tempfile::TempDir;
pub use assertions::*;
pub use marked_text::*;
pub fn temp_tree(tree: serde_json::Value) -> TempDir {
let dir = TempDir::new().unwrap();
write_tree(dir.path(), tree);
dir
pub struct TempTree {
_temp_dir: TempDir,
path: PathBuf,
}
impl TempTree {
pub fn new(tree: serde_json::Value) -> Self {
let dir = TempDir::new().unwrap();
let path = std::fs::canonicalize(dir.path()).unwrap();
write_tree(path.as_path(), tree);
Self {
_temp_dir: dir,
path,
}
}
pub fn path(&self) -> &Path {
self.path.as_path()
}
}
fn write_tree(path: &Path, tree: serde_json::Value) {