-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix mocking methods when a custom Result type is in-scope
There was a hygiene violation in the proc macro. It would cause automock and mock to fail anytime a custom Result type was in scope, even if the mocked method didn't try to use it. Fixes #73
- Loading branch information
Showing
3 changed files
with
56 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,41 @@ | ||
// vim: tw=80 | ||
//! It should be possible to use a custom Result type in the signature of a | ||
//! mocked method. Regression test for | ||
//! https://github.com/asomers/mockall/issues/73 | ||
use mockall::*; | ||
|
||
pub type Result<T> = std::result::Result<T, String>; | ||
|
||
pub struct MyStruct {} | ||
|
||
#[automock] | ||
impl MyStruct { | ||
pub fn ret_static(&self) -> Result<i32> { unimplemented!() } | ||
pub fn ret_ref(&self) -> &Result<i32> { unimplemented!() } | ||
pub fn ret_refmut(&mut self) -> &mut Result<i32> { unimplemented!() } | ||
} | ||
|
||
#[test] | ||
fn ret_ref() { | ||
let mut s = MockMyStruct::new(); | ||
s.expect_ret_ref() | ||
.return_const(Ok(42)); | ||
assert_eq!(Ok(42), *s.ret_ref()); | ||
} | ||
|
||
#[test] | ||
fn ret_ref_mut() { | ||
let mut s = MockMyStruct::new(); | ||
s.expect_ret_refmut() | ||
.return_var(Ok(42)); | ||
assert_eq!(Ok(42), *s.ret_refmut()); | ||
} | ||
|
||
#[test] | ||
fn ret_static() { | ||
let mut s = MockMyStruct::new(); | ||
s.expect_ret_static() | ||
.return_const(Ok(42)); | ||
assert_eq!(Ok(42), s.ret_static()); | ||
} |
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