diff --git a/Cargo.lock b/Cargo.lock index e1dd981e..959c84fe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3302,6 +3302,7 @@ dependencies = [ "open", "percent-encoding", "relative-path", + "same-file", "serde_json", "site", "termcolor", diff --git a/Cargo.toml b/Cargo.toml index 33ec011b..30f897dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,6 +45,9 @@ errors = { path = "components/errors" } front_matter = { path = "components/front_matter" } utils = { path = "components/utils" } +[dev-dependencies] +same-file = "1" + [workspace] members = [ "components/config", diff --git a/src/cmd/init.rs b/src/cmd/init.rs index 1a381737..5ce05f17 100644 --- a/src/cmd/init.rs +++ b/src/cmd/init.rs @@ -250,16 +250,15 @@ mod tests { #[test] fn strip_unc_test() { let mut dir = temp_dir(); - dir.push("new_project"); + dir.push("new_project1"); if dir.exists() { remove_dir_all(&dir).expect("Could not free test directory"); } create_dir(&dir).expect("Could not create test directory"); if cfg!(target_os = "windows") { - assert_eq!( - strip_unc(&canonicalize(Path::new(&dir)).unwrap()), - "C:\\Users\\VssAdministrator\\AppData\\Local\\Temp\\new_project" - ) + let stripped_path = strip_unc(&canonicalize(Path::new(&dir)).unwrap()); + assert!(same_file::is_same_file(Path::new(&stripped_path),&dir).unwrap()); + assert!(!stripped_path.starts_with(LOCAL_UNC),"The path was not stripped."); } else { assert_eq!( strip_unc(&canonicalize(Path::new(&dir)).unwrap()), @@ -277,15 +276,15 @@ mod tests { #[cfg(target_os = "windows")] fn strip_unc_required_test() { let mut dir = temp_dir(); - dir.push("new_project"); + dir.push("new_project2"); if dir.exists() { remove_dir_all(&dir).expect("Could not free test directory"); } create_dir(&dir).expect("Could not create test directory"); - assert_eq!( - canonicalize(Path::new(&dir)).unwrap().to_str().unwrap(), - "\\\\?\\C:\\Users\\VssAdministrator\\AppData\\Local\\Temp\\new_project" - ); + + let canonicalized_path = canonicalize(Path::new(&dir)).unwrap(); + assert!(same_file::is_same_file(Path::new(&canonicalized_path),&dir).unwrap()); + assert!(canonicalized_path.to_str().unwrap().starts_with(LOCAL_UNC)); remove_dir_all(&dir).unwrap(); }