@@ -45,6 +45,12 @@ 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 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
+
48
54
let result = match ( & desc. should_panic , task_result) {
49
55
( & ShouldPanic :: No , Ok ( ( ) ) ) | ( & ShouldPanic :: Yes , Err ( _) ) => TestResult :: TrOk ,
50
56
( & ShouldPanic :: YesWithMessage ( msg) , Err ( err) ) => {
@@ -53,26 +59,32 @@ pub(crate) fn calc_result<'a>(
53
59
. map ( |e| & * * e)
54
60
. or_else ( || err. downcast_ref :: < & ' static str > ( ) . copied ( ) ) ;
55
61
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
+
56
68
if maybe_panic_str. map ( |e| e. contains ( msg) ) . unwrap_or ( false ) {
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#"{shoud_panic_location} 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#"{shoud_panic_location} 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{}" , at_location ) )
76
88
}
77
89
_ => TestResult :: TrFailed ,
78
90
} ;
0 commit comments