@@ -47,7 +47,6 @@ use std::any::Any;
47
47
use std:: borrow:: Cow ;
48
48
use std:: cmp;
49
49
use std:: collections:: BTreeMap ;
50
- use std:: convert:: { TryFrom , TryInto } ;
51
50
use std:: env;
52
51
use std:: fmt;
53
52
use std:: fs:: File ;
@@ -70,6 +69,12 @@ const QUIET_MODE_MAX_COLUMN: usize = 100; // insert a '\n' after 100 tests in qu
70
69
71
70
const SECONDARY_TEST_INVOKER_VAR : & ' static str = "__RUST_TEST_INVOKE" ;
72
71
72
+ // Return codes for secondary process.
73
+ // Start somewhere other than 0 so we know the return code means what we think
74
+ // it means.
75
+ const TR_OK : i32 = 50 ;
76
+ const TR_FAILED : i32 = 51 ;
77
+
73
78
// to be used by rustc to compile tests in libtest
74
79
pub mod test {
75
80
pub use crate :: {
@@ -712,41 +717,6 @@ pub enum TestResult {
712
717
713
718
unsafe impl Send for TestResult { }
714
719
715
- // Return codes for TestResult.
716
- // Start somewhere other than 0 so we know the return code means what we think
717
- // it means.
718
- const TR_OK : i32 = 50 ;
719
- const TR_FAILED : i32 = 51 ;
720
- const TR_IGNORED : i32 = 52 ;
721
- const TR_ALLOWED_FAIL : i32 = 53 ;
722
-
723
- impl TryFrom < TestResult > for i32 {
724
- type Error = & ' static str ;
725
- fn try_from ( val : TestResult ) -> Result < i32 , Self :: Error > {
726
- Ok ( match val {
727
- TrOk => TR_OK ,
728
- TrFailed => TR_FAILED ,
729
- TrIgnored => TR_IGNORED ,
730
- TrAllowedFail => TR_ALLOWED_FAIL ,
731
- TrFailedMsg ( ..) |
732
- TrBench ( ..) => return Err ( "can't convert variant to i32" ) ,
733
- } )
734
- }
735
- }
736
-
737
- impl TryFrom < i32 > for TestResult {
738
- type Error = & ' static str ;
739
- fn try_from ( val : i32 ) -> Result < Self , Self :: Error > {
740
- Ok ( match val {
741
- TR_OK => TrOk ,
742
- TR_FAILED => TrFailed ,
743
- TR_IGNORED => TrIgnored ,
744
- TR_ALLOWED_FAIL => TrAllowedFail ,
745
- _ => return Err ( "unrecognized return code" ) ,
746
- } )
747
- }
748
- }
749
-
750
720
enum OutputLocation < T > {
751
721
Pretty ( Box < term:: StdoutTerminal > ) ,
752
722
Raw ( T ) ,
@@ -1566,6 +1536,15 @@ fn calc_result<'a>(desc: &TestDesc,
1566
1536
}
1567
1537
}
1568
1538
1539
+ fn get_result_from_exit_code ( desc : & TestDesc , code : i32 ) -> TestResult {
1540
+ match ( desc. allow_fail , code) {
1541
+ ( _, TR_OK ) => TrOk ,
1542
+ ( true , TR_FAILED ) => TrAllowedFail ,
1543
+ ( false , TR_FAILED ) => TrFailed ,
1544
+ ( _, _) => TrFailedMsg ( format ! ( "got unexpected return code {}" , code) ) ,
1545
+ }
1546
+ }
1547
+
1569
1548
fn run_test_in_process ( desc : TestDesc ,
1570
1549
nocapture : bool ,
1571
1550
testfn : Box < dyn FnOnce ( ) + Send > ,
@@ -1616,11 +1595,9 @@ fn spawn_test_subprocess(desc: TestDesc, monitor_ch: Sender<MonitorMsg>) {
1616
1595
formatters:: write_stderr_delimiter ( & mut test_output, & desc. name ) ;
1617
1596
test_output. extend_from_slice ( & stderr) ;
1618
1597
1619
- let result = match ( move || {
1598
+ let result = match ( || -> Result < TestResult , String > {
1620
1599
let exit_code = get_exit_code ( status) ?;
1621
- TestResult :: try_from ( exit_code) . map_err ( |_| {
1622
- format ! ( "child process returned unexpected exit code {}" , exit_code)
1623
- } )
1600
+ Ok ( get_result_from_exit_code ( & desc, exit_code) )
1624
1601
} ) ( ) {
1625
1602
Ok ( r) => r,
1626
1603
Err ( e) => {
@@ -1645,18 +1622,19 @@ fn run_test_in_spawned_subprocess(desc: TestDesc, testfn: Box<dyn FnOnce() + Sen
1645
1622
1646
1623
// We don't support serializing TrFailedMsg, so just
1647
1624
// print the message out to stderr.
1648
- let test_result = match test_result {
1649
- TrFailedMsg ( msg) => {
1650
- eprintln ! ( "{}" , msg) ;
1651
- TrFailed
1652
- }
1653
- _ => test_result,
1654
- } ;
1625
+ if let TrFailedMsg ( msg) = & test_result {
1626
+ eprintln ! ( "{}" , msg) ;
1627
+ }
1655
1628
1656
1629
if let Some ( info) = panic_info {
1657
1630
builtin_panic_hook ( info) ;
1658
1631
}
1659
- process:: exit ( test_result. try_into ( ) . unwrap ( ) ) ;
1632
+
1633
+ if let TrOk = test_result {
1634
+ process:: exit ( TR_OK ) ;
1635
+ } else {
1636
+ process:: exit ( TR_FAILED ) ;
1637
+ }
1660
1638
} ) ;
1661
1639
let record_result2 = record_result. clone ( ) ;
1662
1640
panic:: set_hook ( Box :: new ( move |info| record_result2 ( Some ( & info) ) ) ) ;
0 commit comments