From 8b0161ede463c4303bf8126a388f943ce50a13b8 Mon Sep 17 00:00:00 2001 From: hi-rustin Date: Tue, 21 May 2024 20:00:56 +0800 Subject: [PATCH] test: add a test case for removing symlink dir Signed-off-by: hi-rustin --- crates/cargo-util/src/paths.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/crates/cargo-util/src/paths.rs b/crates/cargo-util/src/paths.rs index aed6ce3b1..fe48dd6b1 100644 --- a/crates/cargo-util/src/paths.rs +++ b/crates/cargo-util/src/paths.rs @@ -908,4 +908,27 @@ mod tests { ); } } + + #[test] + #[cfg(windows)] + fn test_remove_symlink_dir() { + use super::*; + use std::fs; + use std::os::windows::fs::symlink_dir; + + let tmpdir = tempfile::tempdir().unwrap(); + let dir_path = tmpdir.path().join("testdir"); + let symlink_path = tmpdir.path().join("symlink"); + + fs::create_dir(&dir_path).unwrap(); + + symlink_dir(&dir_path, &symlink_path).expect("failed to create symlink"); + + assert!(symlink_path.exists()); + + assert!(remove_file(symlink_path.clone()).is_err()); + + assert!(symlink_path.exists()); + assert!(dir_path.exists()); + } }