@@ -45,6 +45,18 @@ pub(crate) fn calc_result<'a>(
45
45
time_opts : Option < & time:: TestTimeOptions > ,
46
46
exec_time : Option < & time:: TestExecTime > ,
47
47
) -> 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
+
48
60
let result = match ( & desc. should_panic , task_result) {
49
61
( & ShouldPanic :: No , Ok ( ( ) ) ) | ( & ShouldPanic :: Yes , Err ( _) ) => TestResult :: TrOk ,
50
62
( & ShouldPanic :: YesWithMessage ( msg) , Err ( err) ) => {
@@ -57,22 +69,22 @@ pub(crate) fn calc_result<'a>(
57
69
TestResult :: TrOk
58
70
} else if let Some ( panic_str) = maybe_panic_str {
59
71
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
61
73
panic message: `{panic_str:?}`,
62
- expected substring: `{msg:?}`"#
74
+ expected substring: `{msg:?}`"#
63
75
) )
64
76
} else {
65
77
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: `{:?}`"# ,
69
81
( * err) . type_id( ) ,
70
82
msg
71
83
) )
72
84
}
73
85
}
74
86
( & 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 ) )
76
88
}
77
89
_ => TestResult :: TrFailed ,
78
90
} ;
0 commit comments