#[cfg(unix)]
use std::ffi::OsStr;
#[cfg(unix)]
use std::fs;
#[cfg(unix)]
use std::os::unix::ffi::OsStrExt;
#[cfg(unix)]
use std::os::unix::fs::symlink;
#[cfg(unix)]
use tempfile::TempDir;
#[cfg(unix)]
#[test]
fn test_symlink_to_non_utf8_path() -> std::io::Result<()> {
let temp_dir = TempDir::new()?;
let base = temp_dir.path();
let non_utf8 = OsStr::from_bytes(b"nonutf8_\xFF");
let target = base.join("target");
fs::create_dir(&target)?;
let link = base.join(non_utf8);
#[cfg(target_os = "macos")]
{
let symlink_result = symlink(&target, &link);
assert!(
symlink_result.is_err(),
"macOS should reject non-UTF8 filenames"
);
let err = symlink_result.unwrap_err();
assert_eq!(err.raw_os_error(), Some(92)); }
#[cfg(not(target_os = "macos"))]
{
symlink(&target, &link)?;
let test_path = link.join("file.txt");
let result = crate::soft_canonicalize(test_path);
assert!(result.is_ok() || result.is_err());
}
Ok(())
}
#[cfg(target_os = "macos")]
#[test]
fn test_macos_utf8_edge_cases() -> std::io::Result<()> {
let temp_dir = TempDir::new()?;
let base = temp_dir.path();
let test_cases = vec![
"normal_path",
"special_ñämé_with_émojî_🦀",
"file with spaces",
"file.with.dots",
"file-with-dashes_and_underscores",
"アニメ", "файл", ];
for case in test_cases {
let target = base.join("target");
fs::create_dir_all(&target)?;
let link = base.join(case);
symlink(&target, &link)?;
let test_path = link.join("file.txt");
let result = crate::soft_canonicalize(test_path);
assert!(result.is_ok() || result.is_err());
if link.exists() {
fs::remove_file(&link)?;
}
if target.exists() {
fs::remove_dir_all(&target)?;
}
}
Ok(())
}