-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #297 from asomers/cfg
Allow #[cfg()] attributes on trait impls in mock!
- Loading branch information
Showing
4 changed files
with
110 additions
and
11 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,65 @@ | ||
// vim: tw=80 | ||
//! mock's methods and trait impls can be conditionally compiled | ||
#![deny(warnings)] | ||
|
||
use mockall::*; | ||
|
||
// For this test, use the "nightly" feature as the cfg gate, because it's tested | ||
// both ways in CI. | ||
#[cfg(feature = "nightly")] | ||
trait Beez { | ||
fn beez(&self); | ||
} | ||
#[cfg(not(feature = "nightly"))] | ||
trait Beez { | ||
fn beez(&self, x: i32) -> i32; | ||
} | ||
|
||
mock! { | ||
pub Foo { | ||
#[cfg(feature = "nightly")] | ||
fn foo(&self); | ||
#[cfg(not(feature = "nightly"))] | ||
fn foo(&self, x: i32) -> i32; | ||
} | ||
#[cfg(feature = "nightly")] | ||
impl Beez for Foo { | ||
fn beez(&self); | ||
} | ||
#[cfg(not(feature = "nightly"))] | ||
impl Beez for Foo { | ||
fn beez(&self, x: i32) -> i32; | ||
} | ||
} | ||
|
||
#[test] | ||
#[cfg(feature = "nightly")] | ||
fn test_nightly_method() { | ||
let mut mock = MockFoo::new(); | ||
mock.expect_foo() | ||
.returning(|| ()); | ||
} | ||
|
||
#[test] | ||
#[cfg(feature = "nightly")] | ||
fn test_nightly_trait() { | ||
let mut mock = MockFoo::new(); | ||
mock.expect_beez() | ||
.returning(|| ()); | ||
} | ||
|
||
#[test] | ||
#[cfg(not(feature = "nightly"))] | ||
fn test_not_nightly_method() { | ||
let mut mock = MockFoo::new(); | ||
mock.expect_foo() | ||
.returning(|x| x + 1); | ||
} | ||
|
||
#[test] | ||
#[cfg(not(feature = "nightly"))] | ||
fn test_not_nightly_trait() { | ||
let mut mock = MockFoo::new(); | ||
mock.expect_beez() | ||
.returning(|x| x + 1); | ||
} |
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