@@ -1731,14 +1731,14 @@ pub fn run_test(
1731
1731
}
1732
1732
1733
1733
struct TestRunOpts {
1734
+ pub strategy : RunStrategy ,
1734
1735
pub nocapture : bool ,
1735
1736
pub concurrency : Concurrent ,
1736
1737
pub time : Option < TestTimeOptions > ,
1737
1738
}
1738
1739
1739
1740
fn run_test_inner (
1740
1741
desc : TestDesc ,
1741
- strategy : RunStrategy ,
1742
1742
monitor_ch : Sender < MonitorMsg > ,
1743
1743
testfn : Box < dyn FnOnce ( ) + Send > ,
1744
1744
opts : TestRunOpts ,
@@ -1747,10 +1747,10 @@ pub fn run_test(
1747
1747
let name = desc. name . clone ( ) ;
1748
1748
1749
1749
let runtest = move || {
1750
- match strategy {
1750
+ match opts . strategy {
1751
1751
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 ) ,
1754
1754
}
1755
1755
} ;
1756
1756
@@ -1767,6 +1767,7 @@ pub fn run_test(
1767
1767
}
1768
1768
1769
1769
let test_run_opts = TestRunOpts {
1770
+ strategy,
1770
1771
nocapture : opts. nocapture ,
1771
1772
concurrency,
1772
1773
time : opts. time_options
@@ -1792,15 +1793,13 @@ pub fn run_test(
1792
1793
} ;
1793
1794
run_test_inner (
1794
1795
desc,
1795
- strategy,
1796
1796
monitor_ch,
1797
1797
Box :: new ( move || __rust_begin_short_backtrace ( f) ) ,
1798
- concurrency
1798
+ test_run_opts ,
1799
1799
) ;
1800
1800
}
1801
1801
StaticTestFn ( f) => run_test_inner (
1802
1802
desc,
1803
- strategy,
1804
1803
monitor_ch,
1805
1804
Box :: new ( move || __rust_begin_short_backtrace ( f) ) ,
1806
1805
test_run_opts,
@@ -1816,10 +1815,10 @@ fn __rust_begin_short_backtrace<F: FnOnce()>(f: F) {
1816
1815
1817
1816
fn calc_result < ' a > (
1818
1817
desc : & TestDesc ,
1819
- task_result : Result < ( ) , & ' a ( dyn Any + ' static + Send ) > )
1818
+ task_result : Result < ( ) , & ' a ( dyn Any + ' static + Send ) > ,
1820
1819
time_opts : & Option < TestTimeOptions > ,
1821
- exec_time : & Option < TestExecTime > )
1822
- -> TestResult {
1820
+ exec_time : & Option < TestExecTime >
1821
+ ) -> TestResult {
1823
1822
let result = match ( & desc. should_panic , task_result) {
1824
1823
( & ShouldPanic :: No , Ok ( ( ) ) ) | ( & ShouldPanic :: Yes , Err ( _) ) => TrOk ,
1825
1824
( & ShouldPanic :: YesWithMessage ( msg) , Err ( ref err) ) => {
@@ -1844,7 +1843,6 @@ fn calc_result<'a>(
1844
1843
_ => TrFailed ,
1845
1844
} ;
1846
1845
1847
-
1848
1846
// If test is already failed (or allowed to fail), do not change the result.
1849
1847
if result != TrOk {
1850
1848
return result;
@@ -1860,20 +1858,42 @@ fn calc_result<'a>(
1860
1858
result
1861
1859
}
1862
1860
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) {
1865
1868
( _, TR_OK ) => TrOk ,
1866
1869
( true , TR_FAILED ) => TrAllowedFail ,
1867
1870
( false , TR_FAILED ) => TrFailed ,
1868
1871
( _, _) => 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
+ }
1869
1884
}
1885
+
1886
+ result
1870
1887
}
1871
1888
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
+ ) {
1877
1897
// Buffer for capturing standard I/O
1878
1898
let data = Arc :: new ( Mutex :: new ( Vec :: new ( ) ) ) ;
1879
1899
@@ -1903,14 +1923,19 @@ fn run_test_in_process(desc: TestDesc,
1903
1923
}
1904
1924
1905
1925
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 ) ,
1908
1928
} ;
1909
1929
let stdout = data. lock ( ) . unwrap ( ) . to_vec ( ) ;
1910
1930
monitor_ch. send ( ( desc. clone ( ) , test_result, exec_time, stdout) ) . unwrap ( ) ;
1911
1931
}
1912
1932
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
+ ) {
1914
1939
let ( result, test_output, exec_time) = ( || {
1915
1940
let args = env:: args ( ) . collect :: < Vec < _ > > ( ) ;
1916
1941
let current_exe = & args[ 0 ] ;
@@ -1941,7 +1966,7 @@ fn spawn_test_subprocess(desc: TestDesc, report_time: bool, monitor_ch: Sender<M
1941
1966
1942
1967
let result = match ( || -> Result < TestResult , String > {
1943
1968
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 ) )
1945
1970
} ) ( ) {
1946
1971
Ok ( r) => r,
1947
1972
Err ( e) => {
@@ -1956,12 +1981,15 @@ fn spawn_test_subprocess(desc: TestDesc, report_time: bool, monitor_ch: Sender<M
1956
1981
monitor_ch. send ( ( desc. clone ( ) , result, exec_time, test_output) ) . unwrap ( ) ;
1957
1982
}
1958
1983
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
+ ) -> ! {
1960
1988
let builtin_panic_hook = panic:: take_hook ( ) ;
1961
1989
let record_result = Arc :: new ( move |panic_info : Option < & ' _ PanicInfo < ' _ > > | {
1962
1990
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 ) ,
1965
1993
} ;
1966
1994
1967
1995
// We don't support serializing TrFailedMsg, so just
0 commit comments