1
1
use std:: any:: Any ;
2
+ use std:: process:: ExitStatus ;
3
+
4
+ #[ cfg( unix) ]
5
+ use std:: os:: unix:: process:: ExitStatusExt ;
2
6
3
7
use super :: bench:: BenchSamples ;
4
8
use super :: options:: ShouldPanic ;
@@ -7,11 +11,16 @@ use super::types::TestDesc;
7
11
8
12
pub use self :: TestResult :: * ;
9
13
10
- // Return codes for secondary process.
14
+ // Return code for secondary process.
11
15
// Start somewhere other than 0 so we know the return code means what we think
12
16
// it means.
13
17
pub 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 ;
15
24
16
25
#[ derive( Debug , Clone , PartialEq ) ]
17
26
pub enum TestResult {
@@ -81,14 +90,28 @@ pub fn calc_result<'a>(
81
90
/// Creates a `TestResult` depending on the exit code of test subprocess.
82
91
pub fn get_result_from_exit_code (
83
92
desc : & TestDesc ,
84
- code : i32 ,
93
+ status : ExitStatus ,
85
94
time_opts : & Option < time:: TestTimeOptions > ,
86
95
exec_time : & Option < time:: TestExecTime > ,
87
96
) -> 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 ,
92
115
} ;
93
116
94
117
// If test is already failed (or allowed to fail), do not change the result.
0 commit comments