-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix some visibility issues with mocking modules and foreign functions:
* When mocking foreign functions, the 'foreign "<ABI>"' block is not a module, and should not introduce an extra layer of visibility modifications. * The visibility of the Expectation must always match the levels argument of Expectation::new(). * When foreign functions, the argument and return types of mocked functions must be superfied by one level. Otherwise code like this wouldn't compile: ```rust struct SuperT; #[automock] extern "Rust" { fn foo(x: super::SuperT) -> super::SuperT; } ```
- Loading branch information
Showing
5 changed files
with
109 additions
and
24 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,57 @@ | ||
// vim: tw=80 | ||
//! "extern" blocks aren't modules, and shouldn't introduce another layer of | ||
//! "super"s. | ||
//! | ||
//! The tests really just check that the visibility of the functions and | ||
//! expectations functions is correct. | ||
#[allow(unused)] | ||
mod outer { | ||
struct SuperT(); | ||
|
||
pub mod inner { | ||
use mockall::automock; | ||
|
||
#[derive(Debug)] | ||
pub(crate) struct PubCrateT(); | ||
#[derive(Debug)] | ||
struct PrivT(); | ||
|
||
#[automock(mod mock_ffi;)] | ||
extern "Rust" { | ||
pub(crate) fn foo(x: PubCrateT) -> PubCrateT; | ||
fn bar(x: PrivT) -> PrivT; | ||
pub(in super) fn baz(x: super::SuperT) -> super::SuperT; | ||
pub(in crate::outer) fn bang(x: crate::outer::SuperT) | ||
-> crate::outer::SuperT; | ||
} | ||
|
||
#[test] | ||
fn test_bar() { | ||
let ctx = mock_ffi::bar_context(); | ||
ctx.expect().returning(|_| PrivT()); | ||
unsafe{mock_ffi::bar(PrivT())}; | ||
} | ||
|
||
|
||
#[test] | ||
fn test_baz() { | ||
let ctx = mock_ffi::baz_context(); | ||
ctx.expect().returning(|_| super::SuperT()); | ||
unsafe{mock_ffi::baz(super::SuperT())}; | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_bang() { | ||
let ctx = inner::mock_ffi::bang_context(); | ||
ctx.expect().returning(|_| SuperT()); | ||
unsafe{inner::mock_ffi::bang(SuperT())}; | ||
} | ||
} | ||
|
||
#[test] | ||
fn foo() { | ||
let ctx = outer::inner::mock_ffi::foo_context(); | ||
ctx.expect().returning(|_| outer::inner::PubCrateT()); | ||
unsafe{outer::inner::mock_ffi::foo(outer::inner::PubCrateT())}; | ||
} |
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
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