@@ -45,6 +45,18 @@ pub(crate) fn calc_result<'a>(
4545 time_opts : Option < & time:: TestTimeOptions > ,
4646 exec_time : Option < & time:: TestExecTime > ,
4747) -> TestResult {
48+ let span_str = if desc. source_file != "" {
49+ format ! ( " at {}:{}:{}" , desc. source_file, desc. start_line, desc. start_col)
50+ } else {
51+ "" . to_string ( )
52+ } ;
53+
54+ let span_should_panic_with_message_didnot_panic = if desc. source_file != "" {
55+ format ! ( "should panic with message{}\n " , span_str)
56+ } else {
57+ "" . to_string ( )
58+ } ;
59+
4860 let result = match ( & desc. should_panic , task_result) {
4961 ( & ShouldPanic :: No , Ok ( ( ) ) ) | ( & ShouldPanic :: Yes , Err ( _) ) => TestResult :: TrOk ,
5062 ( & ShouldPanic :: YesWithMessage ( msg) , Err ( err) ) => {
@@ -57,22 +69,22 @@ pub(crate) fn calc_result<'a>(
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#"{span_should_panic_with_message_didnot_panic} 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#"{span_should_panic_with_message_didnot_panic} 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{}" , span_str ) )
7688 }
7789 _ => TestResult :: TrFailed ,
7890 } ;
0 commit comments