From 25e14bbb0ced1eb20dd135b592427f1c5a3592b8 Mon Sep 17 00:00:00 2001 From: Rayhan Faizel Date: Sat, 10 Jun 2023 18:22:29 +0530 Subject: [PATCH] tests/mv: Test for particular edge cases when handling symlink files --- tests/by-util/test_mv.rs | 48 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/by-util/test_mv.rs b/tests/by-util/test_mv.rs index f73d3249d44..cef95d195d3 100644 --- a/tests/by-util/test_mv.rs +++ b/tests/by-util/test_mv.rs @@ -417,6 +417,54 @@ fn test_mv_same_hardlink() { .stderr_is(format!("mv: '{file_a}' and '{file_b}' are the same file\n",)); } +#[test] +#[cfg(all(unix, not(target_os = "android")))] +fn test_mv_same_symlink() { + let (at, mut ucmd) = at_and_ucmd!(); + let file_a = "test_mv_same_file_a"; + let file_b = "test_mv_same_file_b"; + let file_c = "test_mv_same_file_c"; + + at.touch(file_a); + + at.symlink_file(file_a, file_b); + + ucmd.arg(file_b) + .arg(file_a) + .fails() + .stderr_is(format!("mv: '{file_b}' and '{file_a}' are the same file\n",)); + + let (at2, mut ucmd2) = at_and_ucmd!(); + at2.touch(file_a); + + at2.symlink_file(file_a, file_b); + ucmd2.arg(file_a).arg(file_b).succeeds(); + assert!(at2.file_exists(file_b)); + assert!(!at2.file_exists(file_a)); + + let (at3, mut ucmd3) = at_and_ucmd!(); + at3.touch(file_a); + + at3.symlink_file(file_a, file_b); + at3.symlink_file(file_b, file_c); + + ucmd3.arg(file_c).arg(file_b).succeeds(); + assert!(!at3.symlink_exists(file_c)); + assert!(at3.symlink_exists(file_b)); + + let (at4, mut ucmd4) = at_and_ucmd!(); + at4.touch(file_a); + + at4.symlink_file(file_a, file_b); + at4.symlink_file(file_b, file_c); + + ucmd4 + .arg(file_c) + .arg(file_a) + .fails() + .stderr_is(format!("mv: '{file_c}' and '{file_a}' are the same file\n",)); +} + #[test] #[cfg(all(unix, not(target_os = "android")))] fn test_mv_same_hardlink_backup_simple() {