Skip to content

Commit

Permalink
Fix generation of async partials
Browse files Browse the repository at this point in the history
  • Loading branch information
rubdos authored and la10736 committed Jun 28, 2020
1 parent 0e411c3 commit 72e0d33
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 0 deletions resources/fixture/async_fixture.rs
Expand Up @@ -8,6 +8,11 @@ async fn async_u32() -> u32 {
42
}

#[fixture]
async fn nest_fixture(async_u32: impl Future<Output=u32>) -> u32 {
async_u32.await
}

#[rstest]
async fn default_is_async() {
assert_eq!(42, async_u32::default().await);
Expand Down
15 changes: 13 additions & 2 deletions src/render/fixture.rs
Expand Up @@ -87,18 +87,29 @@ fn render_partial_impl(

let generics = generics_clean_up(&fixture.sig.generics, fn_args(fixture).take(n), &output);
let where_clause = &generics.where_clause;
let asyncness = &fixture.sig.asyncness;

let inject = resolve_args(fn_args_idents(fixture).skip(n), resolver);

let sign_args = fn_args(fixture).take(n);
let fixture_args = fn_args_idents(fixture);
let name = Ident::new(&format!("partial_{}", n), Span::call_site());

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

quote! {
#[allow(unused_mut)]
pub fn #name #generics (#(#sign_args),*) #output #where_clause {
pub #asyncness fn #name #generics (#(#sign_args),*) #output #where_clause {
#inject
Self::get(#(#fixture_args),*)
#self_get
}
}
}
Expand Down

0 comments on commit 72e0d33

Please sign in to comment.