File tree Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -406,7 +406,9 @@ impl CmdResult {
406406 /// Returns the program's exit code
407407 /// Panics if not run or has not finished yet for example when run with `run_no_wait()`
408408 pub fn code ( & self ) -> i32 {
409- self . exit_status ( ) . code ( ) . unwrap ( )
409+ let s = self . exit_status ( ) ;
410+ s. code ( )
411+ . unwrap_or_else ( || panic ! ( "Program did not exit with a status code: {s:?}" ) )
410412 }
411413
412414 /// Verify the exit code of the program
@@ -418,15 +420,29 @@ impl CmdResult {
418420 /// ```
419421 #[ track_caller]
420422 pub fn code_is ( & self , expected_code : i32 ) -> & Self {
421- let fails = self . code ( ) != expected_code;
423+ let fails = self . exit_status ( ) . code ( ) != Some ( expected_code) ;
422424 if fails {
423425 eprintln ! (
424426 "stdout:\n {}\n stderr:\n {}" ,
425427 self . stdout_str( ) ,
426428 self . stderr_str( )
427429 ) ;
428430 }
429- assert_eq ! ( self . code( ) , expected_code) ;
431+ #[ cfg( unix) ]
432+ assert_eq ! (
433+ self . exit_status( ) . code( ) ,
434+ Some ( expected_code) ,
435+ "exit code: {:?}; signal: {:?}" ,
436+ self . exit_status( ) . code( ) ,
437+ self . exit_status( ) . signal( ) ,
438+ ) ;
439+ #[ cfg( not( unix) ) ]
440+ assert_eq ! (
441+ self . exit_status( ) . code( ) ,
442+ Some ( expected_code) ,
443+ "exit code: {:?}" ,
444+ self . exit_status( ) . code( ) ,
445+ ) ;
430446 self
431447 }
432448
You can’t perform that action at this time.
0 commit comments