@@ -24,7 +24,7 @@ use std::{
2424/// test function.
2525///
2626/// ```ignore
27- /// strct MyFixture { ... }
27+ /// struct MyFixture { ... }
2828///
2929/// impl Fixture for MyFixture { ... }
3030///
@@ -54,7 +54,7 @@ pub trait Fixture: Sized {
5454/// a test function.
5555///
5656/// ```ignore
57- /// strct MyFixture { ... }
57+ /// struct MyFixture { ... }
5858///
5959/// impl ConsumableFixture for MyFixture { ... }
6060///
@@ -100,7 +100,7 @@ impl<T> DerefMut for FixtureOf<T> {
100100/// argument to a test function.
101101///
102102/// ```ignore
103- /// strct MyFixture{ ... }
103+ /// struct MyFixture{ ... }
104104///
105105/// impl StaticFixture for MyFixture { ... }
106106///
@@ -214,22 +214,40 @@ mod tests {
214214
215215 #[ test]
216216 #[ 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 ( ) ) )
219219 }
220220
221- struct FailingTearDown ;
221+ struct AbortIfNotTornDownFixture {
222+ has_been_torn_down : bool ,
223+ }
222224
223- impl Fixture for FailingTearDown {
225+ impl Fixture for AbortIfNotTornDownFixture {
224226 fn set_up ( ) -> crate :: Result < Self > {
225- Ok ( Self )
227+ Ok ( Self { has_been_torn_down : false } )
226228 }
229+ fn tear_down ( mut self ) -> crate :: Result < ( ) > {
230+ self . has_been_torn_down = true ;
231+ Ok ( ( ) )
232+ }
233+ }
227234
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+ }
230241 }
231242 }
232243
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+
233251 struct OnlyOnce ;
234252
235253 impl StaticFixture for OnlyOnce {
@@ -263,9 +281,9 @@ mod tests {
263281 #[ test]
264282 fn static_fixture_two_different_static_fixtures ( _: & & OnlyOnce , _: & & AnotherStaticFixture ) { }
265283
266- struct FailingFixture ;
284+ struct FailingSetUp ;
267285
268- impl Fixture for FailingFixture {
286+ impl Fixture for FailingSetUp {
269287 fn set_up ( ) -> crate :: Result < Self > {
270288 Err ( googletest:: TestAssertionFailure :: create ( "sad fixture" . into ( ) ) )
271289 }
@@ -277,5 +295,23 @@ mod tests {
277295
278296 #[ test]
279297 #[ 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 ) { }
281317}
0 commit comments