From 14351f121f6fc8c84b7c6c6eda78ad210e93cfcb Mon Sep 17 00:00:00 2001 From: JJ Liebig Date: Thu, 17 Sep 2026 22:43:35 +0200 Subject: test: skip windows symlink tests without symlink privilege (#4311) Windows refuses file symlinks with ERROR_PRIVILEGE_NOT_HELD (1314) unless the test process is elevated or Developer Mode is enabled, which broke non-admin local runs. Share a helper that reports the missing privilege so the two symlink tests skip only the symlink-dependent assertions. --- src/integration/config_file/tests.rs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'src/integration/config_file') diff --git a/src/integration/config_file/tests.rs b/src/integration/config_file/tests.rs index 916edc67..687767ee 100644 --- a/src/integration/config_file/tests.rs +++ b/src/integration/config_file/tests.rs @@ -1,4 +1,5 @@ use super::*; +use crate::integration::test_support::symlink_file; struct Directory(PathBuf); @@ -103,15 +104,6 @@ fn hard_links_are_rejected_before_staging_and_rechecked_before_commit() { assert_eq!(fs::read_dir(&dir.0).unwrap().count(), 2); } -#[cfg(unix)] -fn symlink(target: &Path, link: &Path) { - std::os::unix::fs::symlink(target, link).unwrap(); -} -#[cfg(windows)] -fn symlink(target: &Path, link: &Path) { - std::os::windows::fs::symlink_file(target, link).unwrap(); -} - #[test] fn symlink_chains_and_dangling_targets_preserve_links() { let dir = Directory::new(); @@ -120,10 +112,12 @@ fn symlink_chains_and_dangling_targets_preserve_links() { let target = other.join("preferences"); let intermediate = other.join("link"); let entry = dir.0.join("config"); - symlink(&target, &intermediate); + if !symlink_file(&target, &intermediate) { + return; + } // A Windows reparse target needs native separators, unlike ordinary Win32 paths. let relative_target = Path::new("other").join("link"); - symlink(&relative_target, &entry); + assert!(symlink_file(&relative_target, &entry)); let original_intermediate = fs::read_link(&intermediate).unwrap(); assert_eq!( fs::metadata(&entry).unwrap_err().kind(), @@ -142,7 +136,7 @@ fn symlink_chains_and_dangling_targets_preserve_links() { assert_eq!(fs::read_link(&entry).unwrap(), relative_target); let cycle = dir.0.join("cycle"); - symlink(Path::new("cycle"), &cycle); + assert!(symlink_file(Path::new("cycle"), &cycle)); assert!(write_config(&cycle, b"must not replace the link").is_err()); assert_eq!(fs::read_link(&cycle).unwrap(), Path::new("cycle")); } -- cgit v1.2.3