Skip to content

Commit f331efc

Browse files
committed
tests/mv: added test case that checks if overwriting a non-empty dir without T flag produces the cannot overwrite error
1 parent c44027b commit f331efc

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/by-util/test_mv.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,6 +1427,32 @@ fn test_mv_overwrite_nonempty_dir() {
14271427
assert!(at.dir_exists(dir_b));
14281428
}
14291429

1430+
#[test]
1431+
fn test_mv_overwrite_nonempty_dir_error() {
1432+
let (at, mut ucmd) = at_and_ucmd!();
1433+
let dir_a = "test_mv_overwrite_nonempty_dir_error_a";
1434+
let dir_b = "test_mv_overwrite_nonempty_dir_error_b";
1435+
let shared_dir = "dir";
1436+
let dummy_dir_a = &format!("{dir_a}/{shared_dir}");
1437+
let dummy_dir_b = &format!("{dir_b}/{shared_dir}");
1438+
let dummy_file = &format!("{dir_b}/{shared_dir}/file");
1439+
1440+
at.mkdir(dir_a);
1441+
at.mkdir(dummy_dir_a);
1442+
at.mkdir(dir_b);
1443+
at.mkdir(dummy_dir_b);
1444+
at.touch(dummy_file);
1445+
1446+
// Not same error as GNU; the error message is a rust builtin as mentioned in
1447+
// https://github.com/uutils/coreutils/issues/5102
1448+
// Current: "mv: cannot overwrite: A non-empty directory: 'b' exists at destination"
1449+
// GNU: "mv: cannot overwrite 'b': Directory not empty"
1450+
1451+
let result = ucmd.arg(dummy_dir_a).arg(dir_b).fails().stderr_is(format!(
1452+
"mv: cannot overwrite: A non-empty directory: '{dummy_dir_b}' exists at destination\n"
1453+
));
1454+
}
1455+
14301456
#[test]
14311457
fn test_mv_backup_dir() {
14321458
let (at, mut ucmd) = at_and_ucmd!();

0 commit comments

Comments
 (0)