1
0
Fork 0
mirror of https://github.com/imjasonh/testscript-rs synced 2026-07-08 09:05:34 +00:00

Fix symlink command implementation and add comprehensive tests (#22)

This commit is contained in:
Copilot 2025-09-27 03:41:07 +00:00 committed by GitHub
parent fdb53b03fa
commit 2705eb5ff2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 110 additions and 3 deletions

View file

@ -181,3 +181,107 @@ hello from stdout"#;
let result = run_test(&script_path);
assert!(result.is_ok(), "CP stdout test failed: {:?}", result);
}
#[cfg(unix)]
#[test]
fn test_symlink_command() {
let temp_dir = TempDir::new().unwrap();
let script_path = temp_dir.path().join("symlink_test.txt");
let script_content = r#"# Test symlink command
symlink original.txt link.txt
exists link.txt
exec cat link.txt
stdout "original content"
-- original.txt --
original content"#;
fs::write(&script_path, script_content).unwrap();
let result = run_test(&script_path);
assert!(result.is_ok(), "Symlink test failed: {:?}", result);
}
#[cfg(unix)]
#[test]
fn test_symlink_directory() {
let temp_dir = TempDir::new().unwrap();
let script_path = temp_dir.path().join("symlink_dir_test.txt");
let script_content = r#"# Test symlink with directory
mkdir test_dir
symlink test_dir link_dir
exists link_dir
exec ls link_dir"#;
fs::write(&script_path, script_content).unwrap();
let result = run_test(&script_path);
assert!(
result.is_ok(),
"Directory symlink test failed: {:?}",
result
);
}
#[cfg(unix)]
#[test]
fn test_symlink_relative_path() {
let temp_dir = TempDir::new().unwrap();
let script_path = temp_dir.path().join("symlink_relative_test.txt");
let script_content = r#"# Test symlink with relative path
mkdir subdir
symlink ../original.txt subdir/link.txt
exists subdir/link.txt
exec cat subdir/link.txt
stdout "relative content"
-- original.txt --
relative content"#;
fs::write(&script_path, script_content).unwrap();
let result = run_test(&script_path);
assert!(
result.is_ok(),
"Relative path symlink test failed: {:?}",
result
);
}
#[test]
fn test_symlink_error_cases() {
let temp_dir = TempDir::new().unwrap();
let script_path = temp_dir.path().join("symlink_error_test.txt");
let script_content = r#"# Test symlink error cases
! symlink
! symlink only_one_arg"#;
fs::write(&script_path, script_content).unwrap();
let result = run_test(&script_path);
assert!(result.is_ok(), "Symlink error test failed: {:?}", result);
}
#[test]
fn test_issue_example() {
let temp_dir = TempDir::new().unwrap();
let script_path = temp_dir.path().join("issue_example.txt");
let script_content = r#"# Create a symlink
symlink original.txt link.txt
exists link.txt
exec cat link.txt
stdout "original content"
-- original.txt --
original content"#;
fs::write(&script_path, script_content).unwrap();
let result = run_test(&script_path);
assert!(result.is_ok(), "Issue example test failed: {:?}", result);
}