1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-30 17:44:34 +01:00

Forward actix_rt::test arguments to test function.

Previously,

```rust
async fn foo(_a: u32) {}
```

would compile to

```rust
fn foo() {/* something */}
```

This patches changes this behaviour to

```rust
fn foo(_a: u32) {/* something */}
```

by simply forwarding the input arguments.

This allows any test fixture library (e.g. `rstest`, cfr.
https://github.com/la10736/rstest/issues/85) to integrate with
actix::test.
This commit is contained in:
Ruben De Smet 2020-04-08 16:48:10 +02:00
parent 65e2e8052e
commit aae52a80ab

View File

@ -58,6 +58,7 @@ pub fn test(_: TokenStream, item: TokenStream) -> TokenStream {
let input = syn::parse_macro_input!(item as syn::ItemFn); let input = syn::parse_macro_input!(item as syn::ItemFn);
let ret = &input.sig.output; let ret = &input.sig.output;
let inputs = &input.sig.inputs;
let name = &input.sig.ident; let name = &input.sig.ident;
let body = &input.block; let body = &input.block;
let attrs = &input.attrs; let attrs = &input.attrs;
@ -81,7 +82,7 @@ pub fn test(_: TokenStream, item: TokenStream) -> TokenStream {
let result = if has_test_attr { let result = if has_test_attr {
quote! { quote! {
#(#attrs)* #(#attrs)*
fn #name() #ret { fn #name(#inputs) #ret {
actix_rt::System::new("test") actix_rt::System::new("test")
.block_on(async { #body }) .block_on(async { #body })
} }
@ -90,7 +91,7 @@ pub fn test(_: TokenStream, item: TokenStream) -> TokenStream {
quote! { quote! {
#[test] #[test]
#(#attrs)* #(#attrs)*
fn #name() #ret { fn #name(#inputs) #ret {
actix_rt::System::new("test") actix_rt::System::new("test")
.block_on(async { #body }) .block_on(async { #body })
} }