Skip to content

Commit

Permalink
Merge pull request #131 from danpintara/pull-1
Browse files Browse the repository at this point in the history
actix-macros: Simplify test macros by using original signature
  • Loading branch information
JohnTitor authored Apr 22, 2020
2 parents 115ef3f + e35c261 commit 7d0cfe1
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions actix-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,11 @@ pub fn main(_: TokenStream, item: TokenStream) -> TokenStream {
/// ```
#[proc_macro_attribute]
pub fn test(_: TokenStream, item: TokenStream) -> TokenStream {
let input = syn::parse_macro_input!(item as syn::ItemFn);

let ret = &input.sig.output;
let inputs = &input.sig.inputs;
let name = &input.sig.ident;
let body = &input.block;
let mut input = syn::parse_macro_input!(item as syn::ItemFn);
let attrs = &input.attrs;
let vis = &input.vis;
let sig = &mut input.sig;
let body = &input.block;
let mut has_test_attr = false;

for attr in attrs {
Expand All @@ -70,7 +68,7 @@ pub fn test(_: TokenStream, item: TokenStream) -> TokenStream {
}
}

if input.sig.asyncness.is_none() {
if sig.asyncness.is_none() {
return syn::Error::new_spanned(
input.sig.fn_token,
format!("only async fn is supported, {}", input.sig.ident),
Expand All @@ -79,10 +77,12 @@ pub fn test(_: TokenStream, item: TokenStream) -> TokenStream {
.into();
}

sig.asyncness = None;

let result = if has_test_attr {
quote! {
#(#attrs)*
fn #name(#inputs) #ret {
#vis #sig {
actix_rt::System::new("test")
.block_on(async { #body })
}
Expand All @@ -91,7 +91,7 @@ pub fn test(_: TokenStream, item: TokenStream) -> TokenStream {
quote! {
#[test]
#(#attrs)*
fn #name(#inputs) #ret {
#vis #sig {
actix_rt::System::new("test")
.block_on(async { #body })
}
Expand Down

0 comments on commit 7d0cfe1

Please sign in to comment.