diff --git a/src/run/commands.rs b/src/run/commands.rs index 2ce1f97..006ea9b 100644 --- a/src/run/commands.rs +++ b/src/run/commands.rs @@ -292,19 +292,12 @@ impl TestEnvironment { // On Windows, try to create a symlink but fall back gracefully use std::os::windows::fs::symlink_file; - if target_path.is_file() { - symlink_file(&target_path, &link_path).map_err(|e| { - Error::command_error( - "symlink", - format!("Cannot create symlink '{}' -> '{}': {} (Note: Windows symlinks may require administrator privileges)", link_name, target, e), - ) - })?; - } else { - return Err(Error::command_error( + symlink_file(&target_path, &link_path).map_err(|e| { + Error::command_error( "symlink", - "Symlinks on Windows are only supported for files, not directories", - )); - } + format!("Cannot create symlink '{}' -> '{}': {} (Note: Windows symlinks may require administrator privileges)", link_name, target, e), + ) + })?; } #[cfg(not(any(unix, windows)))] diff --git a/tests/builtin_commands.rs b/tests/builtin_commands.rs index 7aebc51..9752465 100644 --- a/tests/builtin_commands.rs +++ b/tests/builtin_commands.rs @@ -190,30 +190,50 @@ fn test_symlink_command() { let script_content = r#"# Test symlink command symlink target.txt link.txt exists link.txt +exists target.txt # Test that symlink content matches target exec cat link.txt -stdout "content from target" +stdout "target content" -- target.txt -- -content from target"#; +target content"#; fs::write(&script_path, script_content).unwrap(); let result = run_test(&script_path); - // On Unix systems, this should work + #[cfg(unix)] - assert!(result.is_ok(), "Symlink test failed on Unix: {:?}", result); - - // On Windows, symlinks may fail due to permissions + { + assert!( + result.is_ok(), + "Symlink test should pass on Unix: {:?}", + result + ); + } + #[cfg(windows)] { - if result.is_err() { - let error = result.unwrap_err().to_string(); - assert!(error.contains("symlink") || error.contains("privileges"), - "Unexpected error on Windows: {}", error); + // On Windows, symlinks usually fail due to permissions + if result.is_ok() { + // If it passes on Windows, that means we have admin privileges - that's okay + println!("Symlink test passed on Windows (admin privileges detected)"); + } else { + // Expected failure on Windows due to permissions + let error_msg = result.unwrap_err().to_string(); + assert!(error_msg.contains("symlink"), "Error should mention symlinks: {}", error_msg); } - // If it passes, that's fine too (admin privileges) + } + + #[cfg(not(any(unix, windows)))] + { + // On other platforms, should fail gracefully + assert!( + result.is_err(), + "Symlink should fail on unsupported platforms" + ); + let error_msg = result.unwrap_err().to_string(); + assert!(error_msg.contains("not supported")); } }