Skip to content

Commit

Permalink
mv: Add test & update gnu error
Browse files Browse the repository at this point in the history
  • Loading branch information
PThorpe92 authored and sylvestre committed Sep 24, 2023
1 parent a0904e5 commit 2a95cff
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/by-util/test_mv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,33 @@ fn test_mv_overwrite_nonempty_dir() {
assert!(at.dir_exists(dir_b));
}

#[test]
fn test_mv_nonempty_directory_exists() {
let (at, mut ucmd) = at_and_ucmd!();
let dir_a = "test_mv_nonempty_directory_exists_a";
let dir_b = "test_mv_nonempty_directory_exists_b";
let dummy = "test_mv_nonempty_directory_exists_a/file";
let dummy2 = "test_mv_nonempty_directory_exists_b/file";
at.mkdir(dir_a);
at.mkdir(dir_b);
at.touch(dummy);
at.touch(dummy2);

// Not same error as GNU; the error message is custom.
// GNU: "mv: Couldn't move (Directory not empty; from=a; to=b)
// Current: "mv: Couldn't move {} to {}: A directory exists with the same name at destination"

// Verbose output for the move should not be shown on failure
let result = ucmd.arg("-vT").arg(dir_a).arg(dir_b).fails();
result.no_stdout();
assert!(!result.stderr_str().is_empty());

assert!(at.dir_exists(dir_a));
assert!(at.dir_exists(dir_b));
assert!(at.file_exists(dummy));
assert!(at.file_exists(dummy2));
}

#[test]
fn test_mv_backup_dir() {
let (at, mut ucmd) = at_and_ucmd!();
Expand Down
2 changes: 2 additions & 0 deletions util/build-gnu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ sed -i -e "s|rm: cannot remove 'a/b/file'|rm: cannot remove 'a'|g" tests/rm/cycl

sed -i -e "s|rm: cannot remove directory 'b/a/p'|rm: cannot remove 'b'|g" tests/rm/rm1.sh

sed -i -e "s|mv: cannot move 'b/t' to 'a/t': Directory not empty|mv: cannot move 'b/t' to 'a/t': A directory with the same name exists at destination|g" tests/mv/dir2dir.sh

sed -i -e "s|rm: cannot remove 'a/1'|rm: cannot remove 'a'|g" tests/rm/rm2.sh

sed -i -e "s|removed directory 'a/'|removed directory 'a'|g" tests/rm/v-slash.sh
Expand Down

0 comments on commit 2a95cff

Please sign in to comment.