mirror of
https://github.com/fafhrd91/actix-net
synced 2024-11-27 18:02:58 +01:00
actix-macros: test: Simplify by using #sig instead of #name(#inputs) #ret
This commit is contained in:
parent
115ef3fcb3
commit
e35c261c9f
@ -55,13 +55,11 @@ pub fn main(_: TokenStream, item: TokenStream) -> TokenStream {
|
|||||||
/// ```
|
/// ```
|
||||||
#[proc_macro_attribute]
|
#[proc_macro_attribute]
|
||||||
pub fn test(_: TokenStream, item: TokenStream) -> TokenStream {
|
pub fn test(_: TokenStream, item: TokenStream) -> TokenStream {
|
||||||
let input = syn::parse_macro_input!(item as syn::ItemFn);
|
let mut 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 attrs = &input.attrs;
|
let attrs = &input.attrs;
|
||||||
|
let vis = &input.vis;
|
||||||
|
let sig = &mut input.sig;
|
||||||
|
let body = &input.block;
|
||||||
let mut has_test_attr = false;
|
let mut has_test_attr = false;
|
||||||
|
|
||||||
for attr in attrs {
|
for attr in attrs {
|
||||||
@ -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(
|
return syn::Error::new_spanned(
|
||||||
input.sig.fn_token,
|
input.sig.fn_token,
|
||||||
format!("only async fn is supported, {}", input.sig.ident),
|
format!("only async fn is supported, {}", input.sig.ident),
|
||||||
@ -79,10 +77,12 @@ pub fn test(_: TokenStream, item: TokenStream) -> TokenStream {
|
|||||||
.into();
|
.into();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sig.asyncness = None;
|
||||||
|
|
||||||
let result = if has_test_attr {
|
let result = if has_test_attr {
|
||||||
quote! {
|
quote! {
|
||||||
#(#attrs)*
|
#(#attrs)*
|
||||||
fn #name(#inputs) #ret {
|
#vis #sig {
|
||||||
actix_rt::System::new("test")
|
actix_rt::System::new("test")
|
||||||
.block_on(async { #body })
|
.block_on(async { #body })
|
||||||
}
|
}
|
||||||
@ -91,7 +91,7 @@ pub fn test(_: TokenStream, item: TokenStream) -> TokenStream {
|
|||||||
quote! {
|
quote! {
|
||||||
#[test]
|
#[test]
|
||||||
#(#attrs)*
|
#(#attrs)*
|
||||||
fn #name(#inputs) #ret {
|
#vis #sig {
|
||||||
actix_rt::System::new("test")
|
actix_rt::System::new("test")
|
||||||
.block_on(async { #body })
|
.block_on(async { #body })
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user