@@ -75,9 +75,9 @@ const TEST_WARN_TIMEOUT_S: u64 = 60;
7575// to be used by rustc to compile tests in libtest
7676pub mod test {
7777 pub use { Bencher , TestName , TestResult , TestDesc , TestDescAndFn , TestOpts , TrFailed ,
78- TrIgnored , TrOk , Metric , MetricMap , StaticTestFn , StaticTestName , DynTestName ,
79- DynTestFn , run_test, test_main, test_main_static, filter_tests, parse_opts ,
80- StaticBenchFn , ShouldPanic } ;
78+ TrFailedMsg , TrIgnored , TrOk , Metric , MetricMap , StaticTestFn , StaticTestName ,
79+ DynTestName , DynTestFn , run_test, test_main, test_main_static, filter_tests,
80+ parse_opts , StaticBenchFn , ShouldPanic } ;
8181}
8282
8383pub mod stats;
@@ -473,6 +473,7 @@ pub struct BenchSamples {
473473pub enum TestResult {
474474 TrOk ,
475475 TrFailed ,
476+ TrFailedMsg ( String ) ,
476477 TrIgnored ,
477478 TrMetrics ( MetricMap ) ,
478479 TrBench ( BenchSamples ) ,
@@ -611,7 +612,7 @@ impl<T: Write> ConsoleTestState<T> {
611612 pub fn write_result ( & mut self , result : & TestResult ) -> io:: Result < ( ) > {
612613 match * result {
613614 TrOk => self . write_ok ( ) ,
614- TrFailed => self . write_failed ( ) ,
615+ TrFailed | TrFailedMsg ( _ ) => self . write_failed ( ) ,
615616 TrIgnored => self . write_ignored ( ) ,
616617 TrMetrics ( ref mm) => {
617618 self . write_metric ( ) ?;
@@ -638,6 +639,7 @@ impl<T: Write> ConsoleTestState<T> {
638639 match * result {
639640 TrOk => "ok" . to_owned( ) ,
640641 TrFailed => "failed" . to_owned( ) ,
642+ TrFailedMsg ( ref msg) => format!( "failed: {}" , msg) ,
641643 TrIgnored => "ignored" . to_owned( ) ,
642644 TrMetrics ( ref mm) => mm. fmt_metrics( ) ,
643645 TrBench ( ref bs) => fmt_bench_samples( bs) ,
@@ -773,6 +775,14 @@ pub fn run_tests_console(opts: &TestOpts, tests: Vec<TestDescAndFn>) -> io::Resu
773775 st. failed += 1 ;
774776 st. failures . push ( ( test, stdout) ) ;
775777 }
778+ TrFailedMsg ( msg) => {
779+ st. failed += 1 ;
780+ let mut stdout = stdout;
781+ stdout. extend_from_slice (
782+ format ! ( "note: {}" , msg) . as_bytes ( )
783+ ) ;
784+ st. failures . push ( ( test, stdout) ) ;
785+ }
776786 }
777787 Ok ( ( ) )
778788 }
@@ -1270,12 +1280,16 @@ fn calc_result(desc: &TestDesc, task_result: Result<(), Box<Any + Send>>) -> Tes
12701280 match ( & desc. should_panic , task_result) {
12711281 ( & ShouldPanic :: No , Ok ( ( ) ) ) |
12721282 ( & ShouldPanic :: Yes , Err ( _) ) => TrOk ,
1273- ( & ShouldPanic :: YesWithMessage ( msg) , Err ( ref err) )
1283+ ( & ShouldPanic :: YesWithMessage ( msg) , Err ( ref err) ) =>
12741284 if err. downcast_ref :: < String > ( )
1275- . map ( |e| & * * e)
1276- . or_else ( || err. downcast_ref :: < & ' static str > ( ) . map ( |e| * e) )
1277- . map ( |e| e. contains ( msg) )
1278- . unwrap_or ( false ) => TrOk ,
1285+ . map ( |e| & * * e)
1286+ . or_else ( || err. downcast_ref :: < & ' static str > ( ) . map ( |e| * e) )
1287+ . map ( |e| e. contains ( msg) )
1288+ . unwrap_or ( false ) {
1289+ TrOk
1290+ } else {
1291+ TrFailedMsg ( format ! ( "Panic did not include expected string '{}'" , msg) )
1292+ } ,
12791293 _ => TrFailed ,
12801294 }
12811295}
@@ -1482,8 +1496,9 @@ pub mod bench {
14821496
14831497#[ cfg( test) ]
14841498mod tests {
1485- use test:: { TrFailed , TrIgnored , TrOk , filter_tests, parse_opts, TestDesc , TestDescAndFn ,
1486- TestOpts , run_test, MetricMap , StaticTestName , DynTestName , DynTestFn , ShouldPanic } ;
1499+ use test:: { TrFailed , TrFailedMsg , TrIgnored , TrOk , filter_tests, parse_opts, TestDesc ,
1500+ TestDescAndFn , TestOpts , run_test, MetricMap , StaticTestName , DynTestName ,
1501+ DynTestFn , ShouldPanic } ;
14871502 use std:: sync:: mpsc:: channel;
14881503
14891504 #[ test]
@@ -1565,18 +1580,20 @@ mod tests {
15651580 fn f ( ) {
15661581 panic ! ( "an error message" ) ;
15671582 }
1583+ let expected = "foobar" ;
1584+ let failed_msg = "Panic did not include expected string" ;
15681585 let desc = TestDescAndFn {
15691586 desc : TestDesc {
15701587 name : StaticTestName ( "whatever" ) ,
15711588 ignore : false ,
1572- should_panic : ShouldPanic :: YesWithMessage ( "foobar" ) ,
1589+ should_panic : ShouldPanic :: YesWithMessage ( expected ) ,
15731590 } ,
15741591 testfn : DynTestFn ( Box :: new ( move |( ) | f ( ) ) ) ,
15751592 } ;
15761593 let ( tx, rx) = channel ( ) ;
15771594 run_test ( & TestOpts :: new ( ) , false , desc, tx) ;
15781595 let ( _, res, _) = rx. recv ( ) . unwrap ( ) ;
1579- assert ! ( res == TrFailed ) ;
1596+ assert ! ( res == TrFailedMsg ( format! ( "{} '{}'" , failed_msg , expected ) ) ) ;
15801597 }
15811598
15821599 #[ test]
0 commit comments