@@ -2856,3 +2856,131 @@ fn test_mv_no_prompt_unwriteable_file_with_no_tty() {
28562856 assert ! ( !at. file_exists( "source_notty" ) ) ;
28572857 assert ! ( at. file_exists( "target_notty" ) ) ;
28582858}
2859+
2860+ #[ test]
2861+ #[ cfg( unix) ]
2862+ fn test_mv_dir_symlink_slash_to_dest_dir ( ) {
2863+ let ( at, mut ucmd) = at_and_ucmd ! ( ) ;
2864+
2865+ at. mkdir ( "foo" ) ;
2866+ at. symlink_dir ( "foo" , "symlink" ) ;
2867+
2868+ ucmd. arg ( "symlink/" )
2869+ . arg ( "foo" )
2870+ . fails ( )
2871+ . stderr_contains ( "cannot move 'symlink/' to 'foo/symlink': Not a directory" ) ;
2872+ }
2873+
2874+ #[ test]
2875+ #[ cfg( unix) ]
2876+ fn test_mv_dir_symlink_slash_to_another_dir ( ) {
2877+ let ( at, mut ucmd) = at_and_ucmd ! ( ) ;
2878+
2879+ at. mkdir ( "foo" ) ;
2880+ at. mkdir ( "target" ) ;
2881+ at. symlink_dir ( "foo" , "symlink_foo" ) ;
2882+
2883+ ucmd. arg ( "symlink_foo/" )
2884+ . arg ( "target" )
2885+ . fails ( )
2886+ . stderr_contains ( "cannot move 'symlink_foo/' to 'target/symlink_foo': Not a directory" ) ;
2887+ }
2888+
2889+ #[ test]
2890+ fn test_mv_file_symlink_slash_to_dir ( ) {
2891+ let ( at, mut ucmd) = at_and_ucmd ! ( ) ;
2892+
2893+ at. touch ( "a" ) ;
2894+ at. mkdir ( "target" ) ;
2895+ at. symlink_file ( "a" , "symlink_a" ) ;
2896+
2897+ ucmd. arg ( "symlink/" )
2898+ . arg ( "target" )
2899+ . fails ( )
2900+ . stderr_contains ( "cannot stat 'symlink/': Not a directory" ) ;
2901+ }
2902+
2903+ #[ test]
2904+ #[ cfg( unix) ]
2905+ fn test_mv_dir_symlink_slash_to_file ( ) {
2906+ let ( at, mut ucmd) = at_and_ucmd ! ( ) ;
2907+
2908+ at. touch ( "a" ) ;
2909+ at. mkdir ( "foo" ) ;
2910+ at. symlink_dir ( "foo" , "symlink_foo" ) ;
2911+
2912+ ucmd. arg ( "symlink_foo/" )
2913+ . arg ( "a" )
2914+ . fails ( )
2915+ . stderr_contains ( "cannot overwrite non-directory 'a' with directory 'symlink_foo/'" ) ;
2916+ }
2917+
2918+ #[ test]
2919+ #[ cfg( windows) ]
2920+ fn test_mv_dir_symlink_slash_to_dest_dir ( ) {
2921+ let ( at, mut ucmd) = at_and_ucmd ! ( ) ;
2922+
2923+ at. mkdir ( "foo" ) ;
2924+ at. symlink_dir ( "foo" , "symlink" ) ;
2925+
2926+ ucmd. arg ( "symlink/" )
2927+ . arg ( "foo" )
2928+ . fails ( )
2929+ . stderr_contains ( "cannot stat 'symlink/': Not a directory" ) ;
2930+ }
2931+
2932+ #[ test]
2933+ #[ cfg( windows) ]
2934+ fn test_mv_dir_symlink_slash_to_another_dir ( ) {
2935+ let ( at, mut ucmd) = at_and_ucmd ! ( ) ;
2936+
2937+ at. mkdir ( "foo" ) ;
2938+ at. mkdir ( "target" ) ;
2939+ at. symlink_dir ( "foo" , "symlink_foo" ) ;
2940+
2941+ ucmd. arg ( "symlink_foo/" )
2942+ . arg ( "target" )
2943+ . fails ( )
2944+ . stderr_contains ( "cannot stat 'symlink_foo/': Not a directory" ) ;
2945+ }
2946+
2947+ #[ test]
2948+ #[ cfg( windows) ]
2949+ fn test_mv_dir_symlink_slash_to_file ( ) {
2950+ let ( at, mut ucmd) = at_and_ucmd ! ( ) ;
2951+
2952+ at. touch ( "a" ) ;
2953+ at. mkdir ( "foo" ) ;
2954+ at. symlink_dir ( "foo" , "symlink_foo" ) ;
2955+
2956+ ucmd. arg ( "symlink_foo/" )
2957+ . arg ( "a" )
2958+ . fails ( )
2959+ . stderr_contains ( "cannot stat 'symlink_foo/': Not a directory" ) ;
2960+ }
2961+
2962+ #[ test]
2963+ fn test_mv_file_symlink_slash_to_dest_file ( ) {
2964+ let ( at, mut ucmd) = at_and_ucmd ! ( ) ;
2965+ at. touch ( "a" ) ;
2966+ at. symlink_dir ( "a" , "symlink_a" ) ;
2967+
2968+ ucmd. arg ( "symlink_a/" )
2969+ . arg ( "a" )
2970+ . fails ( )
2971+ . stderr_contains ( "cannot stat 'symlink_a/': Not a directory" ) ;
2972+ }
2973+ #[ test]
2974+ fn test_mv_file_symlink_slash_to_another_file ( ) {
2975+ let ( at, mut ucmd) = at_and_ucmd ! ( ) ;
2976+ at. touch ( "a" ) ;
2977+ at. touch ( "b" ) ;
2978+ at. symlink_dir ( "a" , "symlink_a" ) ;
2979+
2980+ ucmd. arg ( "symlink_a/" )
2981+ . arg ( "b" )
2982+ . fails ( )
2983+ . stderr_contains ( "cannot stat 'symlink_a/': Not a directory" ) ;
2984+ }
2985+
2986+
0 commit comments