@@ -119,7 +119,7 @@ fn test_mv_move_file_into_file_with_target_arg() {
119119 . arg ( file1)
120120 . arg ( file2)
121121 . fails ( )
122- . stderr_is ( format ! ( "mv: target directory '{file1}': Not a directory\n " ) ) ;
122+ . stderr_only ( format ! ( "mv: target directory '{file1}': Not a directory\n " ) ) ;
123123
124124 assert ! ( at. file_exists( file1) ) ;
125125}
@@ -139,7 +139,7 @@ fn test_mv_move_multiple_files_into_file() {
139139 . arg ( file2)
140140 . arg ( file3)
141141 . fails ( )
142- . stderr_is ( format ! ( "mv: target '{file3}': Not a directory\n " ) ) ;
142+ . stderr_only ( format ! ( "mv: target '{file3}': Not a directory\n " ) ) ;
143143
144144 assert ! ( at. file_exists( file1) ) ;
145145 assert ! ( at. file_exists( file2) ) ;
@@ -332,7 +332,7 @@ fn test_mv_interactive_no_clobber_force_last_arg_wins() {
332332 . ucmd ( )
333333 . args ( & [ file_a, file_b, "-n" , "-f" , "-i" ] )
334334 . fails ( )
335- . stderr_is ( format ! ( "mv: overwrite '{file_b}'? " ) ) ;
335+ . stderr_only ( format ! ( "mv: overwrite '{file_b}'? " ) ) ;
336336
337337 at. write ( file_a, "aa" ) ;
338338
@@ -518,7 +518,7 @@ fn test_mv_same_file() {
518518 ucmd. arg ( file_a)
519519 . arg ( file_a)
520520 . fails ( )
521- . stderr_is ( format ! ( "mv: '{file_a}' and '{file_a}' are the same file\n " ) ) ;
521+ . stderr_only ( format ! ( "mv: '{file_a}' and '{file_a}' are the same file\n " ) ) ;
522522}
523523
524524#[ test]
@@ -535,7 +535,7 @@ fn test_mv_same_hardlink() {
535535 ucmd. arg ( file_a)
536536 . arg ( file_b)
537537 . fails ( )
538- . stderr_is ( format ! ( "mv: '{file_a}' and '{file_b}' are the same file\n " ) ) ;
538+ . stderr_only ( format ! ( "mv: '{file_a}' and '{file_b}' are the same file\n " ) ) ;
539539}
540540
541541#[ test]
@@ -566,7 +566,7 @@ fn test_mv_same_symlink() {
566566 ucmd. arg ( file_b)
567567 . arg ( file_a)
568568 . fails ( )
569- . stderr_is ( format ! ( "mv: '{file_b}' and '{file_a}' are the same file\n " ) ) ;
569+ . stderr_only ( format ! ( "mv: '{file_b}' and '{file_a}' are the same file\n " ) ) ;
570570
571571 let ( at2, mut ucmd2) = at_and_ucmd ! ( ) ;
572572 at2. touch ( file_a) ;
@@ -596,7 +596,7 @@ fn test_mv_same_symlink() {
596596 . arg ( file_c)
597597 . arg ( file_a)
598598 . fails ( )
599- . stderr_is ( format ! ( "mv: '{file_c}' and '{file_a}' are the same file\n " ) ) ;
599+ . stderr_only ( format ! ( "mv: '{file_c}' and '{file_a}' are the same file\n " ) ) ;
600600}
601601
602602#[ test]
@@ -609,7 +609,7 @@ fn test_mv_same_broken_symlink() {
609609 ucmd. arg ( "broken" )
610610 . arg ( "broken" )
611611 . fails ( )
612- . stderr_is ( "mv: 'broken' and 'broken' are the same file\n " ) ;
612+ . stderr_only ( "mv: 'broken' and 'broken' are the same file\n " ) ;
613613}
614614
615615#[ test]
@@ -742,7 +742,7 @@ fn test_mv_same_file_not_dot_dir() {
742742 let dir = "test_mv_errors_dir" ;
743743
744744 at. mkdir ( dir) ;
745- ucmd. arg ( dir) . arg ( dir) . fails ( ) . stderr_is ( format ! (
745+ ucmd. arg ( dir) . arg ( dir) . fails ( ) . stderr_only ( format ! (
746746 "mv: cannot move '{dir}' to a subdirectory of itself, '{dir}/{dir}'\n " ,
747747 ) ) ;
748748}
@@ -754,7 +754,7 @@ fn test_mv_same_file_dot_dir() {
754754 ucmd. arg ( "." )
755755 . arg ( "." )
756756 . fails ( )
757- . stderr_is ( "mv: '.' and '.' are the same file\n " ) ;
757+ . stderr_only ( "mv: '.' and '.' are the same file\n " ) ;
758758}
759759
760760#[ test]
@@ -1487,15 +1487,35 @@ fn test_mv_overwrite_nonempty_dir() {
14871487 at. mkdir ( dir_a) ;
14881488 at. mkdir ( dir_b) ;
14891489 at. touch ( dummy) ;
1490- // Not same error as GNU; the error message is a rust builtin
1491- // TODO: test (and implement) correct error message (or at least decide whether to do so)
1492- // Current: "mv: couldn't rename path (Directory not empty; from=a; to=b)"
1493- // GNU: "mv: cannot move 'a' to 'b': Directory not empty"
1494-
14951490 // Verbose output for the move should not be shown on failure
1496- let result = ucmd. arg ( "-vT" ) . arg ( dir_a) . arg ( dir_b) . fails ( ) ;
1497- result. no_stdout ( ) ;
1498- assert ! ( !result. stderr_str( ) . is_empty( ) ) ;
1491+ ucmd. arg ( "-vT" )
1492+ . arg ( dir_a)
1493+ . arg ( dir_b)
1494+ . fails ( )
1495+ . stderr_only ( format ! (
1496+ "mv: cannot overwrite destination '{dir_b}': Directory not empty\n "
1497+ ) ) ;
1498+
1499+ assert ! ( at. dir_exists( dir_a) ) ;
1500+ assert ! ( at. dir_exists( dir_b) ) ;
1501+ }
1502+
1503+ #[ test]
1504+ fn test_mv_overwrite_nonempty_dir_into_dir ( ) {
1505+ let ( at, mut ucmd) = at_and_ucmd ! ( ) ;
1506+ let dir_a = "test_mv_overwrite_nonempty_dir_into_dir_a" ;
1507+ let dir_b = "test_mv_overwrite_nonempty_dir_into_dir_b" ;
1508+ let target_dir = format ! ( "{dir_b}/{dir_a}" ) ;
1509+ let dummy = format ! ( "{target_dir}/file" ) ;
1510+
1511+ at. mkdir ( dir_a) ;
1512+ at. mkdir ( dir_b) ;
1513+ at. mkdir ( & target_dir) ;
1514+ at. touch ( & dummy) ;
1515+
1516+ ucmd. arg ( dir_a) . arg ( dir_b) . fails ( ) . stderr_only ( format ! (
1517+ "mv: cannot overwrite destination '{dir_b}/{dir_a}': Directory not empty\n "
1518+ ) ) ;
14991519
15001520 assert ! ( at. dir_exists( dir_a) ) ;
15011521 assert ! ( at. dir_exists( dir_b) ) ;
@@ -1534,7 +1554,6 @@ fn test_mv_errors() {
15341554 at. touch ( file_b) ;
15351555
15361556 // $ mv -T -t a b
1537- // mv: cannot combine --target-directory (-t) and --no-target-directory (-T)
15381557 scene
15391558 . ucmd ( )
15401559 . arg ( "-T" )
@@ -1547,29 +1566,26 @@ fn test_mv_errors() {
15471566
15481567 // $ at.touch file && at.mkdir dir
15491568 // $ mv -T file dir
1550- // err == mv: cannot overwrite directory 'dir' with non-directory
15511569 scene
15521570 . ucmd ( )
15531571 . arg ( "-T" )
15541572 . arg ( file_a)
15551573 . arg ( dir)
15561574 . fails ( )
1557- . stderr_is ( format ! (
1575+ . stderr_only ( format ! (
15581576 "mv: cannot overwrite directory '{dir}' with non-directory\n "
15591577 ) ) ;
15601578
15611579 // $ at.mkdir dir && at.touch file
15621580 // $ mv dir file
1563- // err == mv: cannot overwrite non-directory 'file' with directory 'dir'
1564- assert ! (
1565- !scene
1566- . ucmd( )
1567- . arg( dir)
1568- . arg( file_a)
1569- . fails( )
1570- . stderr_str( )
1571- . is_empty( )
1572- ) ;
1581+ scene
1582+ . ucmd ( )
1583+ . arg ( dir)
1584+ . arg ( file_a)
1585+ . fails ( )
1586+ . stderr_only ( format ! (
1587+ "mv: cannot overwrite directory '{dir}' with non-directory\n "
1588+ ) ) ;
15731589}
15741590
15751591#[ test]
@@ -1656,8 +1672,7 @@ fn test_mv_arg_interactive_skipped() {
16561672 . pipe_in ( "N\n " )
16571673 . ignore_stdin_write_error ( )
16581674 . fails ( )
1659- . stderr_is ( "mv: overwrite 'b'? " )
1660- . no_stdout ( ) ;
1675+ . stderr_only ( "mv: overwrite 'b'? " ) ;
16611676}
16621677
16631678#[ test]
0 commit comments