11use std:: any:: Any ;
2+ use std:: process:: ExitStatus ;
3+
4+ #[ cfg( unix) ]
5+ use std:: os:: unix:: process:: ExitStatusExt ;
26
37use super :: bench:: BenchSamples ;
48use super :: options:: ShouldPanic ;
@@ -7,11 +11,16 @@ use super::types::TestDesc;
711
812pub use self :: TestResult :: * ;
913
10- // Return codes for secondary process.
14+ // Return code for secondary process.
1115// Start somewhere other than 0 so we know the return code means what we think
1216// it means.
1317pub const TR_OK : i32 = 50 ;
14- pub const TR_FAILED : i32 = 51 ;
18+
19+ #[ cfg( unix) ]
20+ const SIGABRT : i32 = 6 ;
21+
22+ #[ cfg( windows) ]
23+ const EXIT_ABORTED : i32 = 3 ;
1524
1625#[ derive( Debug , Clone , PartialEq ) ]
1726pub enum TestResult {
@@ -81,14 +90,28 @@ pub fn calc_result<'a>(
8190/// Creates a `TestResult` depending on the exit code of test subprocess.
8291pub fn get_result_from_exit_code (
8392 desc : & TestDesc ,
84- code : i32 ,
93+ status : ExitStatus ,
8594 time_opts : & Option < time:: TestTimeOptions > ,
8695 exec_time : & Option < time:: TestExecTime > ,
8796) -> TestResult {
88- let result = match code {
89- TR_OK => TestResult :: TrOk ,
90- TR_FAILED => TestResult :: TrFailed ,
91- _ => TestResult :: TrFailedMsg ( format ! ( "got unexpected return code {code}" ) ) ,
97+ let result = match status. code ( ) {
98+ Some ( TR_OK ) => TestResult :: TrOk ,
99+ #[ cfg( windows) ]
100+ Some ( EXIT_ABORTED ) => TestResult :: TrFailed ,
101+ #[ cfg( unix) ]
102+ None => match status. signal ( ) {
103+ Some ( SIGABRT ) => TestResult :: TrFailed ,
104+ Some ( signal) => {
105+ TestResult :: TrFailedMsg ( format ! ( "child process exited with signal {signal}" ) )
106+ }
107+ None => unreachable ! ( "status.code() returned None but status.signal() was None" ) ,
108+ } ,
109+ #[ cfg( not( unix) ) ]
110+ None => TestResult :: TrFailedMsg ( format ! ( "unknown return code" ) ) ,
111+ #[ cfg( any( windows, unix) ) ]
112+ Some ( code) => TestResult :: TrFailedMsg ( format ! ( "got unexpected return code {code}" ) ) ,
113+ #[ cfg( not( any( windows, unix) ) ) ]
114+ Some ( _) => TestResult :: TrFailed ,
92115 } ;
93116
94117 // If test is already failed (or allowed to fail), do not change the result.
0 commit comments