diff options
| author | HampusM <hampus@hampusmat.com> | 2023-03-19 18:06:28 +0100 | 
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2023-03-19 18:06:28 +0100 | 
| commit | f73c3218b9a004fb405386ce2623d2dfa077388c (patch) | |
| tree | 5e8a43741ac00e7f265e45d64fa3d1afdfe367f6 /macros | |
| parent | ad2a6d1dc517407939ed022bba9f3352efc678ce (diff) | |
fix: allow mocking methods taking &mut self
Diffstat (limited to 'macros')
| -rw-r--r-- | macros/src/expectation.rs | 36 | ||||
| -rw-r--r-- | macros/src/mock.rs | 2 | 
2 files changed, 3 insertions, 35 deletions
diff --git a/macros/src/expectation.rs b/macros/src/expectation.rs index 436d571..5a4922c 100644 --- a/macros/src/expectation.rs +++ b/macros/src/expectation.rs @@ -16,9 +16,6 @@ use syn::{      ImplItemMethod,      ItemStruct,      Lifetime, -    Pat, -    PatIdent, -    PatType,      Path,      PathSegment,      Receiver, @@ -268,35 +265,6 @@ impl ToTokens for Expectation              self.return_type.clone(),          )); -        let args = opt_self_type -            .iter() -            .chain(self.arg_types.iter()) -            .enumerate() -            .map(|(index, ty)| { -                FnArg::Typed(PatType { -                    attrs: vec![], -                    pat: Box::new(Pat::Ident(PatIdent { -                        attrs: vec![], -                        by_ref: None, -                        mutability: None, -                        ident: format_ident!("arg_{index}"), -                        subpat: None, -                    })), -                    colon_token: <Token![:]>::default(), -                    ty: Box::new(ty.clone()), -                }) -            }) -            .collect::<Vec<_>>(); - -        let arg_idents = opt_self_type -            .iter() -            .chain(self.arg_types.iter()) -            .enumerate() -            .map(|(index, _)| format_ident!("arg_{index}")) -            .collect::<Vec<_>>(); - -        let return_type = &self.return_type; -          let method_ident = &self.method_ident;          let expectation_struct = Self::create_struct( @@ -358,7 +326,7 @@ impl ToTokens for Expectation                      unsafe { std::mem::transmute(self) }                  } -                fn call_returning(&self, #(#args),*) #return_type +                fn get_returning(&self) -> &#returning_fn                  {                      let Some(returning) = &self.returning else {                          panic!(concat!( @@ -398,7 +366,7 @@ impl ToTokens for Expectation                      self.call_cnt.fetch_add(1, std::sync::atomic::Ordering::Relaxed); -                    (returning)(#(#arg_idents),*) +                    returning                  }              } diff --git a/macros/src/mock.rs b/macros/src/mock.rs index d2eb451..2ac27e5 100644 --- a/macros/src/mock.rs +++ b/macros/src/mock.rs @@ -247,7 +247,7 @@ fn create_mock_function(                      ))                      .with_generic_params::<#(#type_param_idents,)*>(); -                expectation.call_returning(#(#args),*) +                (expectation.get_returning())(#(#args),*)              }          })          .unwrap_or_abort(),  | 
