@@ -1731,14 +1731,14 @@ pub fn run_test(
17311731 }
17321732
17331733 struct TestRunOpts {
1734+ pub strategy : RunStrategy ,
17341735 pub nocapture : bool ,
17351736 pub concurrency : Concurrent ,
17361737 pub time : Option < TestTimeOptions > ,
17371738 }
17381739
17391740 fn run_test_inner (
17401741 desc : TestDesc ,
1741- strategy : RunStrategy ,
17421742 monitor_ch : Sender < MonitorMsg > ,
17431743 testfn : Box < dyn FnOnce ( ) + Send > ,
17441744 opts : TestRunOpts ,
@@ -1747,10 +1747,10 @@ pub fn run_test(
17471747 let name = desc. name . clone ( ) ;
17481748
17491749 let runtest = move || {
1750- match strategy {
1750+ match opts . strategy {
17511751 RunStrategy :: InProcess =>
1752- run_test_in_process ( desc, nocapture, report_time , testfn, monitor_ch) ,
1753- RunStrategy :: SpawnPrimary => spawn_test_subprocess ( desc, report_time , monitor_ch) ,
1752+ run_test_in_process ( desc, opts . nocapture , opts . time . is_some ( ) , testfn, monitor_ch, opts . time ) ,
1753+ RunStrategy :: SpawnPrimary => spawn_test_subprocess ( desc, opts . time . is_some ( ) , monitor_ch, opts . time ) ,
17541754 }
17551755 } ;
17561756
@@ -1767,6 +1767,7 @@ pub fn run_test(
17671767 }
17681768
17691769 let test_run_opts = TestRunOpts {
1770+ strategy,
17701771 nocapture : opts. nocapture ,
17711772 concurrency,
17721773 time : opts. time_options
@@ -1792,15 +1793,13 @@ pub fn run_test(
17921793 } ;
17931794 run_test_inner (
17941795 desc,
1795- strategy,
17961796 monitor_ch,
17971797 Box :: new ( move || __rust_begin_short_backtrace ( f) ) ,
1798- concurrency
1798+ test_run_opts ,
17991799 ) ;
18001800 }
18011801 StaticTestFn ( f) => run_test_inner (
18021802 desc,
1803- strategy,
18041803 monitor_ch,
18051804 Box :: new ( move || __rust_begin_short_backtrace ( f) ) ,
18061805 test_run_opts,
@@ -1816,10 +1815,10 @@ fn __rust_begin_short_backtrace<F: FnOnce()>(f: F) {
18161815
18171816fn calc_result < ' a > (
18181817 desc : & TestDesc ,
1819- task_result : Result < ( ) , & ' a ( dyn Any + ' static + Send ) > )
1818+ task_result : Result < ( ) , & ' a ( dyn Any + ' static + Send ) > ,
18201819 time_opts : & Option < TestTimeOptions > ,
1821- exec_time : & Option < TestExecTime > )
1822- -> TestResult {
1820+ exec_time : & Option < TestExecTime >
1821+ ) -> TestResult {
18231822 let result = match ( & desc. should_panic , task_result) {
18241823 ( & ShouldPanic :: No , Ok ( ( ) ) ) | ( & ShouldPanic :: Yes , Err ( _) ) => TrOk ,
18251824 ( & ShouldPanic :: YesWithMessage ( msg) , Err ( ref err) ) => {
@@ -1844,7 +1843,6 @@ fn calc_result<'a>(
18441843 _ => TrFailed ,
18451844 } ;
18461845
1847-
18481846 // If test is already failed (or allowed to fail), do not change the result.
18491847 if result != TrOk {
18501848 return result;
@@ -1860,20 +1858,42 @@ fn calc_result<'a>(
18601858 result
18611859}
18621860
1863- fn get_result_from_exit_code ( desc : & TestDesc , code : i32 ) -> TestResult {
1864- match ( desc. allow_fail , code) {
1861+ fn get_result_from_exit_code (
1862+ desc : & TestDesc ,
1863+ code : i32 ,
1864+ time_opts : & Option < TestTimeOptions > ,
1865+ exec_time : & Option < TestExecTime > ,
1866+ ) -> TestResult {
1867+ let result = match ( desc. allow_fail , code) {
18651868 ( _, TR_OK ) => TrOk ,
18661869 ( true , TR_FAILED ) => TrAllowedFail ,
18671870 ( false , TR_FAILED ) => TrFailed ,
18681871 ( _, _) => TrFailedMsg ( format ! ( "got unexpected return code {}" , code) ) ,
1872+ } ;
1873+
1874+ // If test is already failed (or allowed to fail), do not change the result.
1875+ if result != TrOk {
1876+ return result;
1877+ }
1878+
1879+ // Check if test is failed due to timeout.
1880+ if let ( Some ( opts) , Some ( time) ) = ( time_opts, exec_time) {
1881+ if opts. error_on_excess && opts. is_critical ( desc, time) {
1882+ return TrTimedFail ;
1883+ }
18691884 }
1885+
1886+ result
18701887}
18711888
1872- fn run_test_in_process ( desc : TestDesc ,
1873- nocapture : bool ,
1874- report_time : bool ,
1875- testfn : Box < dyn FnOnce ( ) + Send > ,
1876- monitor_ch : Sender < MonitorMsg > ) {
1889+ fn run_test_in_process (
1890+ desc : TestDesc ,
1891+ nocapture : bool ,
1892+ report_time : bool ,
1893+ testfn : Box < dyn FnOnce ( ) + Send > ,
1894+ monitor_ch : Sender < MonitorMsg > ,
1895+ time_opts : Option < TestTimeOptions > ,
1896+ ) {
18771897 // Buffer for capturing standard I/O
18781898 let data = Arc :: new ( Mutex :: new ( Vec :: new ( ) ) ) ;
18791899
@@ -1903,14 +1923,19 @@ fn run_test_in_process(desc: TestDesc,
19031923 }
19041924
19051925 let test_result = match result {
1906- Ok ( ( ) ) => calc_result ( & desc, Ok ( ( ) ) ) ,
1907- Err ( e) => calc_result ( & desc, Err ( e. as_ref ( ) ) ) ,
1926+ Ok ( ( ) ) => calc_result ( & desc, Ok ( ( ) ) , & time_opts , & exec_time ) ,
1927+ Err ( e) => calc_result ( & desc, Err ( e. as_ref ( ) ) , & time_opts , & exec_time ) ,
19081928 } ;
19091929 let stdout = data. lock ( ) . unwrap ( ) . to_vec ( ) ;
19101930 monitor_ch. send ( ( desc. clone ( ) , test_result, exec_time, stdout) ) . unwrap ( ) ;
19111931}
19121932
1913- fn spawn_test_subprocess ( desc : TestDesc , report_time : bool , monitor_ch : Sender < MonitorMsg > ) {
1933+ fn spawn_test_subprocess (
1934+ desc : TestDesc ,
1935+ report_time : bool ,
1936+ monitor_ch : Sender < MonitorMsg > ,
1937+ time_opts : Option < TestTimeOptions > ,
1938+ ) {
19141939 let ( result, test_output, exec_time) = ( || {
19151940 let args = env:: args ( ) . collect :: < Vec < _ > > ( ) ;
19161941 let current_exe = & args[ 0 ] ;
@@ -1941,7 +1966,7 @@ fn spawn_test_subprocess(desc: TestDesc, report_time: bool, monitor_ch: Sender<M
19411966
19421967 let result = match ( || -> Result < TestResult , String > {
19431968 let exit_code = get_exit_code ( status) ?;
1944- Ok ( get_result_from_exit_code ( & desc, exit_code) )
1969+ Ok ( get_result_from_exit_code ( & desc, exit_code, & time_opts , & exec_time ) )
19451970 } ) ( ) {
19461971 Ok ( r) => r,
19471972 Err ( e) => {
@@ -1956,12 +1981,15 @@ fn spawn_test_subprocess(desc: TestDesc, report_time: bool, monitor_ch: Sender<M
19561981 monitor_ch. send ( ( desc. clone ( ) , result, exec_time, test_output) ) . unwrap ( ) ;
19571982}
19581983
1959- fn run_test_in_spawned_subprocess ( desc : TestDesc , testfn : Box < dyn FnOnce ( ) + Send > ) -> ! {
1984+ fn run_test_in_spawned_subprocess (
1985+ desc : TestDesc ,
1986+ testfn : Box < dyn FnOnce ( ) + Send > ,
1987+ ) -> ! {
19601988 let builtin_panic_hook = panic:: take_hook ( ) ;
19611989 let record_result = Arc :: new ( move |panic_info : Option < & ' _ PanicInfo < ' _ > > | {
19621990 let test_result = match panic_info {
1963- Some ( info) => calc_result ( & desc, Err ( info. payload ( ) ) ) ,
1964- None => calc_result ( & desc, Ok ( ( ) ) ) ,
1991+ Some ( info) => calc_result ( & desc, Err ( info. payload ( ) ) , & None , & None ) ,
1992+ None => calc_result ( & desc, Ok ( ( ) ) , & None , & None ) ,
19651993 } ;
19661994
19671995 // We don't support serializing TrFailedMsg, so just
0 commit comments