@@ -206,6 +206,44 @@ fn read_from_stdin() -> Result<(), Box<dyn std::error::Error>> {
206206 Ok ( ( ) )
207207}
208208
209+ #[ test]
210+ fn missing_file_as_empty ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
211+ let tmp_dir = tempdir ( ) ?;
212+ let present = tmp_dir. path ( ) . join ( "present" ) ;
213+ let absent = tmp_dir. path ( ) . join ( "absent" ) ;
214+ std:: fs:: write ( & present, "kiwi\n mango\n " ) ?;
215+
216+ for option in [ "-N" , "--new-file" , "--unidirectional-new-file" ] {
217+ let mut cmd = cargo_bin_cmd ! ( "diffutils" ) ;
218+ cmd. arg ( "diff" ) . arg ( option) . arg ( & absent) . arg ( & present) ;
219+ cmd. assert ( )
220+ . code ( predicate:: eq ( 1 ) )
221+ . failure ( )
222+ . stdout ( "0a1,2\n > kiwi\n > mango\n " ) ;
223+ }
224+
225+ let mut cmd = cargo_bin_cmd ! ( "diffutils" ) ;
226+ cmd. arg ( "diff" ) . arg ( "-N" ) . arg ( & present) . arg ( & absent) ;
227+ cmd. assert ( )
228+ . code ( predicate:: eq ( 1 ) )
229+ . failure ( )
230+ . stdout ( "1,2d0\n < kiwi\n < mango\n " ) ;
231+
232+ // Only a missing first operand is accepted here.
233+ let mut cmd = cargo_bin_cmd ! ( "diffutils" ) ;
234+ cmd. arg ( "diff" )
235+ . arg ( "--unidirectional-new-file" )
236+ . arg ( & present)
237+ . arg ( & absent) ;
238+ cmd. assert ( ) . code ( predicate:: eq ( 2 ) ) . failure ( ) ;
239+
240+ // Without the option, a missing file is trouble.
241+ let mut cmd = cargo_bin_cmd ! ( "diffutils" ) ;
242+ cmd. arg ( "diff" ) . arg ( & absent) . arg ( & present) ;
243+ cmd. assert ( ) . code ( predicate:: eq ( 2 ) ) . failure ( ) ;
244+ Ok ( ( ) )
245+ }
246+
209247#[ test]
210248fn compare_file_to_directory ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
211249 let tmp_dir = tempdir ( ) ?;
0 commit comments