mv: symlinks as files, tests

This commit is contained in:
id3v1669 2025-08-30 15:58:50 +08:00
parent c3a1fdfb7b
commit c53b5dbce5

View file

@ -398,6 +398,78 @@ fn test_mv_replace_file() {
assert!(at.file_exists(file_b));
}
#[test]
#[cfg(all(unix, not(target_os = "android")))]
fn test_mv_replace_symlink_with_symlink() {
let (at, mut ucmd) = at_and_ucmd!();
at.mkdir("a");
at.mkdir("b");
at.touch("a/empty_file_a");
at.touch("b/empty_file_b");
at.symlink_dir("a", "symlink_a");
at.symlink_dir("b", "symlink_b");
assert_eq!(at.read("symlink_a/empty_file_a"), "");
ucmd.arg("-T")
.arg("symlink_b")
.arg("symlink_a")
.succeeds()
.no_stderr();
assert!(at.file_exists("symlink_a/empty_file_b"));
assert!(!at.file_exists("symlink_a/empty_file_a"));
assert!(!at.symlink_exists("symlink_b"));
}
#[test]
#[cfg(all(unix, not(target_os = "android")))]
fn test_mv_replace_symlink_with_directory() {
let (at, mut ucmd) = at_and_ucmd!();
at.mkdir("a");
at.mkdir("b");
at.touch("a/empty_file_a");
at.touch("b/empty_file_b");
at.symlink_dir("a", "symlink");
ucmd.arg("-T")
.arg("b")
.arg("symlink")
.fails()
.stderr_contains("cannot overwrite non-directory")
.stderr_contains("with directory");
}
#[test]
#[cfg(all(unix, not(target_os = "android")))]
fn test_mv_replace_symlink_with_file() {
let (at, mut ucmd) = at_and_ucmd!();
at.mkdir("a");
at.touch("a/empty_file_a");
at.touch("empty_file_b");
at.symlink_dir("a", "symlink");
assert!(at.file_exists("symlink/empty_file_a"));
ucmd.arg("-T")
.arg("empty_file_b")
.arg("symlink")
.succeeds()
.no_stderr();
assert!(at.file_exists("symlink"));
assert!(!at.is_symlink("symlink"));
assert!(!at.file_exists("empty_file_b"));
assert!(at.dir_exists("a"));
assert!(at.file_exists("a/empty_file_a"));
}
#[test]
fn test_mv_force_replace_file() {
let (at, mut ucmd) = at_and_ucmd!();