Skip to content

Commit

Permalink
Carry asyncness over into fixture code
Browse files Browse the repository at this point in the history
  • Loading branch information
rubdos committed Apr 10, 2020
1 parent b6ed1d9 commit 0ce8763
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/render/fixture.rs
Expand Up @@ -10,6 +10,7 @@ use crate::utils::{fn_args, fn_args_idents};

pub(crate) fn render<'a>(fixture: ItemFn, info: FixtureInfo) -> TokenStream {
let name = &fixture.sig.ident;
let asyncness = &fixture.sig.asyncness.clone();
let vargs = fn_args_idents(&fixture).cloned().collect::<Vec<_>>();
let args = &vargs;
let orig_args = &fixture.sig.inputs;
Expand All @@ -29,20 +30,37 @@ pub(crate) fn render<'a>(fixture: ItemFn, info: FixtureInfo) -> TokenStream {
let inject = resolve_args(fn_args_idents(&fixture), &resolver);
let partials =
(1..=orig_args.len()).map(|n| render_partial_impl(&fixture, n, &resolver, &info));

let (self_get_default, self_get) = if asyncness.is_none() {
(
quote! {
Self::get(#(#args),*)
},
quote! {#name(#(#args),*)},
)
} else {
(
quote! {
Self::get(#(#args),*).await
},
quote! {#name(#(#args),*).await},
)
};

quote! {
#[allow(non_camel_case_types)]
#visibility struct #name {}

impl #name {
#(#orig_attrs)*
#[allow(unused_mut)]
pub fn get #generics (#orig_args) #output #where_clause {
#name(#(#args),*)
pub #asyncness fn get #generics (#orig_args) #output #where_clause {
#self_get
}

pub fn default #default_generics () #default_output #default_where_clause {
pub #asyncness fn default #default_generics () #default_output #default_where_clause {
#inject
Self::get(#(#args),*)
#self_get_default
}

#(#partials)*
Expand Down

0 comments on commit 0ce8763

Please sign in to comment.