@@ -45,6 +45,12 @@ pub(crate) fn calc_result<'a>(
4545 time_opts : Option < & time:: TestTimeOptions > ,
4646 exec_time : Option < & time:: TestExecTime > ,
4747) -> TestResult {
48+ let at_location = if desc. source_file != "" {
49+ format ! ( " at {}:{}:{}" , desc. source_file, desc. start_line, desc. start_col)
50+ } else {
51+ "" . to_string ( )
52+ } ;
53+
4854 let result = match ( & desc. should_panic , task_result) {
4955 ( & ShouldPanic :: No , Ok ( ( ) ) ) | ( & ShouldPanic :: Yes , Err ( _) ) => TestResult :: TrOk ,
5056 ( & ShouldPanic :: YesWithMessage ( msg) , Err ( err) ) => {
@@ -53,26 +59,32 @@ pub(crate) fn calc_result<'a>(
5359 . map ( |e| & * * e)
5460 . or_else ( || err. downcast_ref :: < & ' static str > ( ) . copied ( ) ) ;
5561
62+ let shoud_panic_location = if desc. source_file != "" {
63+ format ! ( "should panic with message{}\n " , at_location)
64+ } else {
65+ "" . to_string ( )
66+ } ;
67+
5668 if maybe_panic_str. map ( |e| e. contains ( msg) ) . unwrap_or ( false ) {
5769 TestResult :: TrOk
5870 } else if let Some ( panic_str) = maybe_panic_str {
5971 TestResult :: TrFailedMsg ( format ! (
60- r#"panic did not contain expected string
72+ r#"{shoud_panic_location} panic did not contain expected string
6173 panic message: `{panic_str:?}`,
62- expected substring: `{msg:?}`"#
74+ expected substring: `{msg:?}`"#
6375 ) )
6476 } else {
6577 TestResult :: TrFailedMsg ( format ! (
66- r#"expected panic with string value,
67- found non-string value: `{:?}`
68- expected substring: `{:?}`"# ,
78+ r#"{shoud_panic_location} expected panic with string value,
79+ found non-string value: `{:?}`
80+ expected substring: `{:?}`"# ,
6981 ( * err) . type_id( ) ,
7082 msg
7183 ) )
7284 }
7385 }
7486 ( & ShouldPanic :: Yes , Ok ( ( ) ) ) | ( & ShouldPanic :: YesWithMessage ( _) , Ok ( ( ) ) ) => {
75- TestResult :: TrFailedMsg ( "test did not panic as expected" . to_string ( ) )
87+ TestResult :: TrFailedMsg ( format ! ( "test did not panic as expected{}" , at_location ) )
7688 }
7789 _ => TestResult :: TrFailed ,
7890 } ;
0 commit comments