-
Notifications
You must be signed in to change notification settings - Fork 59
/
mock_debug.rs
40 lines (35 loc) · 838 Bytes
/
mock_debug.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// 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 { }
impl Clone for Bar {
fn clone(&self) -> Self;
}
}
// With no derive(Debug), mockall won't genetate the debug impl automatically
mock!{
pub Baz { }
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));
}