-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Always drop static methods' Expectations during Drop
Even if a panic is in-progress. Originally we didn't drop them during panic, for fear of double-panicing. But there is already protection from double-panic in Common::drop. Not clearing expectations during a panic can cause surprising failures in one test case after a different test case panics. Fixes #442
- Loading branch information
Showing
3 changed files
with
37 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// vim: tw=80 | ||
//! Static methods' expectations should be dropped during panic. | ||
//! | ||
//! https://github.com/asomers/mockall/issues/442 | ||
#![deny(warnings)] | ||
|
||
use std::panic; | ||
|
||
use mockall::*; | ||
|
||
#[automock] | ||
pub trait Foo { | ||
fn foo() -> i32; | ||
} | ||
|
||
#[test] | ||
fn drop_expectations_on_panic() { | ||
panic::catch_unwind(|| { | ||
let ctx = MockFoo::foo_context(); | ||
ctx.expect() | ||
.times(1) | ||
.return_const(42); | ||
panic!("Panicking!"); | ||
}).unwrap_err(); | ||
|
||
// The previously set expectation should've been cleared during the panic, | ||
// so we must set a new one. | ||
let ctx = MockFoo::foo_context(); | ||
ctx.expect() | ||
.times(1) | ||
.return_const(42); | ||
assert_eq!(42, MockFoo::foo()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters