@@ -24,7 +24,7 @@ use std::{
24
24
/// test function.
25
25
///
26
26
/// ```ignore
27
- /// strct MyFixture { ... }
27
+ /// struct MyFixture { ... }
28
28
///
29
29
/// impl Fixture for MyFixture { ... }
30
30
///
@@ -54,7 +54,7 @@ pub trait Fixture: Sized {
54
54
/// a test function.
55
55
///
56
56
/// ```ignore
57
- /// strct MyFixture { ... }
57
+ /// struct MyFixture { ... }
58
58
///
59
59
/// impl ConsumableFixture for MyFixture { ... }
60
60
///
@@ -100,7 +100,7 @@ impl<T> DerefMut for FixtureOf<T> {
100
100
/// argument to a test function.
101
101
///
102
102
/// ```ignore
103
- /// strct MyFixture{ ... }
103
+ /// struct MyFixture{ ... }
104
104
///
105
105
/// impl StaticFixture for MyFixture { ... }
106
106
///
@@ -214,22 +214,40 @@ mod tests {
214
214
215
215
#[ test]
216
216
#[ should_panic( expected = "Whoooops" ) ]
217
- fn fixture_teardown_called_even_if_test_fail ( _: & PanickyFixture ) {
218
- panic ! ( "Test failed" ) ;
217
+ fn fixture_teardown_called_even_if_test_fail ( _: & PanickyFixture ) -> Result < ( ) > {
218
+ Err ( googletest :: TestAssertionFailure :: create ( "It must fail!" . into ( ) ) )
219
219
}
220
220
221
- struct FailingTearDown ;
221
+ struct AbortIfNotTornDownFixture {
222
+ has_been_torn_down : bool ,
223
+ }
222
224
223
- impl Fixture for FailingTearDown {
225
+ impl Fixture for AbortIfNotTornDownFixture {
224
226
fn set_up ( ) -> crate :: Result < Self > {
225
- Ok ( Self )
227
+ Ok ( Self { has_been_torn_down : false } )
226
228
}
229
+ fn tear_down ( mut self ) -> crate :: Result < ( ) > {
230
+ self . has_been_torn_down = true ;
231
+ Ok ( ( ) )
232
+ }
233
+ }
227
234
228
- fn tear_down ( self ) -> crate :: Result < ( ) > {
229
- Err ( googletest:: TestAssertionFailure :: create ( "It must fail!" . into ( ) ) )
235
+ impl Drop for AbortIfNotTornDownFixture {
236
+ fn drop ( & mut self ) {
237
+ if !self . has_been_torn_down {
238
+ eprintln ! ( "AbortIfNotTornDownFixture was not torn down" ) ;
239
+ std:: process:: abort ( ) ;
240
+ }
230
241
}
231
242
}
232
243
244
+ #[ test]
245
+ #[ should_panic( expected = "simple_fail" ) ]
246
+ fn fixture_torn_down_after_test_panics ( f : & AbortIfNotTornDownFixture ) {
247
+ expect_that ! ( f. has_been_torn_down, eq( false ) ) ;
248
+ panic ! ( "simple_fail" ) ;
249
+ }
250
+
233
251
struct OnlyOnce ;
234
252
235
253
impl StaticFixture for OnlyOnce {
@@ -263,9 +281,9 @@ mod tests {
263
281
#[ test]
264
282
fn static_fixture_two_different_static_fixtures ( _: & & OnlyOnce , _: & & AnotherStaticFixture ) { }
265
283
266
- struct FailingFixture ;
284
+ struct FailingSetUp ;
267
285
268
- impl Fixture for FailingFixture {
286
+ impl Fixture for FailingSetUp {
269
287
fn set_up ( ) -> crate :: Result < Self > {
270
288
Err ( googletest:: TestAssertionFailure :: create ( "sad fixture" . into ( ) ) )
271
289
}
@@ -277,5 +295,23 @@ mod tests {
277
295
278
296
#[ test]
279
297
#[ should_panic( expected = "See failure output above" ) ]
280
- fn failing_fixture_causes_test_failure ( _: & FailingFixture ) { }
298
+ fn failing_fixture_causes_test_failure ( _: & FailingSetUp ) {
299
+ unreachable ! ( )
300
+ }
301
+
302
+ struct FailingTearDown ;
303
+
304
+ impl Fixture for FailingTearDown {
305
+ fn set_up ( ) -> crate :: Result < Self > {
306
+ Ok ( Self )
307
+ }
308
+
309
+ fn tear_down ( self ) -> crate :: Result < ( ) > {
310
+ Err ( googletest:: TestAssertionFailure :: create ( "It must fail!" . into ( ) ) )
311
+ }
312
+ }
313
+
314
+ #[ test]
315
+ #[ should_panic( expected = "See failure output above" ) ]
316
+ fn failing_teardown_causes_test_failure ( _: & FailingTearDown ) { }
281
317
}
0 commit comments