Skip to content

Commit

Permalink
Add a test case for Isseu #610
Browse files Browse the repository at this point in the history
automock wrongly removes elided lifetimes from structs

Issue #610
  • Loading branch information
asomers committed Oct 6, 2024
1 parent 97c31d2 commit acedd79
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions mockall/tests/automock_elided_lifetime.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// vim: tw=80
//! Mock a struct with a lifetime parameter
#![deny(warnings)]

use mockall::*;

pub struct NonStaticStruct<'nss> {
_x: &'nss i32
}

#[automock]
impl NonStaticStruct<'_> {
pub fn foo(&self) -> i64 {
42
}
}

#[test]
fn normal_method() {
// This function serves to define a named lifetime
fn has_lt<'a>(_x: &'a i8) -> MockNonStaticStruct<'a> {
MockNonStaticStruct::<'a>::default()
}

let x = 42i8;
let mut mock = has_lt(&x);
mock.expect_foo()
.returning(|| 5);
assert_eq!(5, mock.foo());
}

0 comments on commit acedd79

Please sign in to comment.