File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -175,7 +175,8 @@ fn reader_writer<
175175 }
176176 }
177177 ReadResult :: EmptyInput => {
178- // don't output anything
178+ // output empty too, as coreutils does
179+ print_sorted ( vec ! [ ] . iter ( ) , settings, output) ?;
179180 }
180181 }
181182 Ok ( ( ) )
Original file line number Diff line number Diff line change @@ -34,6 +34,8 @@ pub fn ext_sort(
3434 file?. read_to_end ( & mut input) ?;
3535 }
3636 if input. is_empty ( ) {
37+ // empty files are sorted to empty like in coreutils
38+ print_sorted ( chunk. lines ( ) . iter ( ) , settings, output) ?;
3739 return Ok ( ( ) ) ;
3840 }
3941 let mut chunk = Chunk :: try_new ( input, |buffer| {
Original file line number Diff line number Diff line change @@ -2960,4 +2960,17 @@ e f 5436 down data path1 path2 path3 path4 path5\n";
29602960 . stdout_is ( input) ;
29612961}
29622962
2963+ #[ test]
2964+ fn test_empty_input_empty_output ( ) {
2965+ // check for inconsistency #11958
2966+ let input = "test test test" ;
2967+ let ( at, mut ucmd) = at_and_ucmd ! ( ) ;
2968+
2969+ at. touch ( "file" ) ;
2970+ at. append ( "file" , input) ;
2971+
2972+ ucmd. args ( & [ "-o" , "file" ] ) . pipe_in ( "" ) . succeeds ( ) ;
2973+ assert_eq ! ( at. read( "file" ) , "" ) ;
2974+ }
2975+
29632976/* spell-checker: enable */
You can’t perform that action at this time.
0 commit comments