#![deny(warnings)]
use mockall::*;
#[derive(Clone)]
struct X<'a>(&'a u32);
trait T {
fn trait_method(&self) -> X<'_>;
}
mock! {
Foo {
fn inherent_method(&self) -> X<'_>;
}
impl T for Foo {
fn trait_method(&self) -> X<'_>;
}
}
mod return_nonstatic {
use super::*;
#[test]
fn inherent_method() {
let d = 42u32;
let x = X(&d);
let xstatic: X<'static> = unsafe{ std::mem::transmute(x) };
let mut mock = MockFoo::new();
mock.expect_inherent_method()
.returning(move || xstatic.clone());
assert_eq!(42u32, *mock.inherent_method().0);
}
#[test]
fn trait_method() {
let d = 42u32;
let x = X(&d);
let xstatic: X<'static> = unsafe{ std::mem::transmute(x) };
let mut mock = MockFoo::new();
mock.expect_trait_method()
.returning(move || xstatic.clone());
assert_eq!(42u32, *mock.trait_method().0);
}
}