Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions crates/ts_goport/tests/build_watch_parses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,26 @@ fn scratch_dir_in(base: &Path, test: &str) -> PathBuf {
std::process::id()
));
fs::create_dir(&dir).unwrap_or_else(|error| panic!("create {}: {error}", dir.display()));
if cfg!(windows) {
return dir;
// tsc names the watched directories by the real path, so the test must
// too: on Windows the temp dir can be a short name (`RUNNER~1`), and an
// edit under it then reaches no watch.
let real = fs::canonicalize(&dir).expect("canonical scratch dir");
// On Windows the real path is verbatim (`\\?\C:\...`), which tsc does not
// take as a cwd.
#[cfg(windows)]
let real = PathBuf::from(unverbatim(&real.to_string_lossy()));
real
}

/// `text` without the Windows verbatim prefix: `\\?\C:\x` is `C:\x`, and
/// `\\?\UNC\server\share\x` is `\\server\share\x` (the root stays).
#[cfg(windows)]
fn unverbatim(text: &str) -> String {
if let Some(unc) = text.strip_prefix("\\\\?\\UNC\\") {
format!("\\\\{unc}")
} else {
text.strip_prefix("\\\\?\\").unwrap_or(text).to_owned()
}
fs::canonicalize(&dir).expect("canonical scratch dir")
}

fn copy_dir(from: &Path, to: &Path) {
Expand Down