-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically generate Debug impls for mock structs
Fixes #287
- Loading branch information
Showing
7 changed files
with
171 additions
and
2 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
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,35 @@ | ||
// vim: tw=80 | ||
//! A mocked struct should implement Debug | ||
#![deny(warnings)] | ||
|
||
use mockall::*; | ||
|
||
#[automock] | ||
pub trait Foo {} | ||
|
||
pub trait Bar {} | ||
pub struct Baz {} | ||
#[automock] | ||
impl Bar for Baz{} | ||
|
||
pub struct Bean {} | ||
#[automock] | ||
impl Bean{} | ||
|
||
#[test] | ||
fn automock_trait() { | ||
let foo = MockFoo::new(); | ||
assert_eq!("MockFoo", format!("{:?}", foo)); | ||
} | ||
|
||
#[test] | ||
fn automock_struct_impl() { | ||
let bean = MockBean::new(); | ||
assert_eq!("MockBean", format!("{:?}", bean)); | ||
} | ||
|
||
#[test] | ||
fn automock_trait_impl() { | ||
let baz = MockBaz::new(); | ||
assert_eq!("MockBaz", format!("{:?}", baz)); | ||
} |
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,44 @@ | ||
// vim: tw=80 | ||
//! A mocked struct should implement Debug | ||
#![deny(warnings)] | ||
|
||
use mockall::*; | ||
use std::fmt::{self, Debug, Formatter}; | ||
|
||
// using derive(Debug) tells mockall to generate the Debug impl automatically | ||
mock!{ | ||
#[derive(Debug)] | ||
pub Bar { | ||
fn foo(&self) -> u32; | ||
} | ||
impl Clone for Bar { | ||
fn clone(&self) -> Self; | ||
} | ||
} | ||
|
||
// With no derive(Debug), mockall won't genetate the debug impl automatically | ||
mock!{ | ||
pub Baz { | ||
fn foo(&self) -> u32; | ||
} | ||
impl Clone for Baz { | ||
fn clone(&self) -> Self; | ||
} | ||
} | ||
impl Debug for MockBaz { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), fmt::Error> { | ||
f.debug_struct("XXX").finish() | ||
} | ||
} | ||
|
||
#[test] | ||
fn automatic() { | ||
let bar = MockBar::new(); | ||
assert_eq!("MockBar", format!("{:?}", bar)); | ||
} | ||
|
||
#[test] | ||
fn manual() { | ||
let baz = MockBaz::new(); | ||
assert_eq!("XXX", format!("{:?}", baz)); | ||
} |
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