@@ -15,6 +15,7 @@ use crate::{
15
15
// TestType, TrFailedMsg, TrIgnored, TrOk,
16
16
} ,
17
17
} ;
18
+ use std:: any:: TypeId ;
18
19
use std:: sync:: mpsc:: channel;
19
20
use std:: time:: Duration ;
20
21
@@ -84,7 +85,7 @@ pub fn do_not_run_ignored_tests() {
84
85
let ( tx, rx) = channel ( ) ;
85
86
run_test ( & TestOpts :: new ( ) , false , desc, RunStrategy :: InProcess , tx, Concurrent :: No ) ;
86
87
let result = rx. recv ( ) . unwrap ( ) . result ;
87
- assert ! ( result != TrOk ) ;
88
+ assert_ne ! ( result, TrOk ) ;
88
89
}
89
90
90
91
#[ test]
@@ -103,7 +104,7 @@ pub fn ignored_tests_result_in_ignored() {
103
104
let ( tx, rx) = channel ( ) ;
104
105
run_test ( & TestOpts :: new ( ) , false , desc, RunStrategy :: InProcess , tx, Concurrent :: No ) ;
105
106
let result = rx. recv ( ) . unwrap ( ) . result ;
106
- assert ! ( result == TrIgnored ) ;
107
+ assert_eq ! ( result, TrIgnored ) ;
107
108
}
108
109
109
110
// FIXME: Re-enable emscripten once it can catch panics again (introduced by #65251)
@@ -126,7 +127,7 @@ fn test_should_panic() {
126
127
let ( tx, rx) = channel ( ) ;
127
128
run_test ( & TestOpts :: new ( ) , false , desc, RunStrategy :: InProcess , tx, Concurrent :: No ) ;
128
129
let result = rx. recv ( ) . unwrap ( ) . result ;
129
- assert ! ( result == TrOk ) ;
130
+ assert_eq ! ( result, TrOk ) ;
130
131
}
131
132
132
133
// FIXME: Re-enable emscripten once it can catch panics again (introduced by #65251)
@@ -149,7 +150,7 @@ fn test_should_panic_good_message() {
149
150
let ( tx, rx) = channel ( ) ;
150
151
run_test ( & TestOpts :: new ( ) , false , desc, RunStrategy :: InProcess , tx, Concurrent :: No ) ;
151
152
let result = rx. recv ( ) . unwrap ( ) . result ;
152
- assert ! ( result == TrOk ) ;
153
+ assert_eq ! ( result, TrOk ) ;
153
154
}
154
155
155
156
// FIXME: Re-enable emscripten once it can catch panics again (introduced by #65251)
@@ -161,7 +162,9 @@ fn test_should_panic_bad_message() {
161
162
panic ! ( "an error message" ) ;
162
163
}
163
164
let expected = "foobar" ;
164
- let failed_msg = "panic did not include expected string" ;
165
+ let failed_msg = r#"panic did not contain expected string
166
+ panic message: `"an error message"`,
167
+ expected substring: `"foobar"`"# ;
165
168
let desc = TestDescAndFn {
166
169
desc : TestDesc {
167
170
name : StaticTestName ( "whatever" ) ,
@@ -175,7 +178,35 @@ fn test_should_panic_bad_message() {
175
178
let ( tx, rx) = channel ( ) ;
176
179
run_test ( & TestOpts :: new ( ) , false , desc, RunStrategy :: InProcess , tx, Concurrent :: No ) ;
177
180
let result = rx. recv ( ) . unwrap ( ) . result ;
178
- assert ! ( result == TrFailedMsg ( format!( "{} '{}'" , failed_msg, expected) ) ) ;
181
+ assert_eq ! ( result, TrFailedMsg ( failed_msg. to_string( ) ) ) ;
182
+ }
183
+
184
+ // FIXME: Re-enable emscripten once it can catch panics again (introduced by #65251)
185
+ #[ test]
186
+ #[ cfg( not( target_os = "emscripten" ) ) ]
187
+ fn test_should_panic_non_string_message_type ( ) {
188
+ use crate :: tests:: TrFailedMsg ;
189
+ fn f ( ) {
190
+ panic ! ( 1i32 ) ;
191
+ }
192
+ let expected = "foobar" ;
193
+ let failed_msg = format ! ( r#"expected panic with string value,
194
+ found non-string value: `{:?}`
195
+ expected substring: `"foobar"`"# , TypeId :: of:: <i32 >( ) ) ;
196
+ let desc = TestDescAndFn {
197
+ desc : TestDesc {
198
+ name : StaticTestName ( "whatever" ) ,
199
+ ignore : false ,
200
+ should_panic : ShouldPanic :: YesWithMessage ( expected) ,
201
+ allow_fail : false ,
202
+ test_type : TestType :: Unknown ,
203
+ } ,
204
+ testfn : DynTestFn ( Box :: new ( f) ) ,
205
+ } ;
206
+ let ( tx, rx) = channel ( ) ;
207
+ run_test ( & TestOpts :: new ( ) , false , desc, RunStrategy :: InProcess , tx, Concurrent :: No ) ;
208
+ let result = rx. recv ( ) . unwrap ( ) . result ;
209
+ assert_eq ! ( result, TrFailedMsg ( failed_msg) ) ;
179
210
}
180
211
181
212
// FIXME: Re-enable emscripten once it can catch panics again (introduced by #65251)
@@ -196,7 +227,7 @@ fn test_should_panic_but_succeeds() {
196
227
let ( tx, rx) = channel ( ) ;
197
228
run_test ( & TestOpts :: new ( ) , false , desc, RunStrategy :: InProcess , tx, Concurrent :: No ) ;
198
229
let result = rx. recv ( ) . unwrap ( ) . result ;
199
- assert ! ( result == TrFailedMsg ( "test did not panic as expected" . to_string( ) ) ) ;
230
+ assert_eq ! ( result, TrFailedMsg ( "test did not panic as expected" . to_string( ) ) ) ;
200
231
}
201
232
202
233
fn report_time_test_template ( report_time : bool ) -> Option < TestExecTime > {
@@ -570,7 +601,7 @@ pub fn sort_tests() {
570
601
] ;
571
602
572
603
for ( a, b) in expected. iter ( ) . zip ( filtered) {
573
- assert ! ( * a == b. desc. name. to_string( ) ) ;
604
+ assert_eq ! ( * a, b. desc. name. to_string( ) ) ;
574
605
}
575
606
}
576
607
0 commit comments