Forward actix_rt::test arguments to test function. by rubdos · Pull Request #127 · actix/actix-net (original) (raw)

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation4 Commits1 Checks0 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

rubdos

Previously,

#[actix_rt::test] async fn foo(_a: u32) {}

would compile to

#[test] fn foo() {/* something */}

This patches changes this behaviour to

#[test] fn foo(_a: u32) {/* something */}

by simply forwarding the input arguments.

This allows any test fixture library (e.g. rstest, cfr. la10736/rstest#85) to integrate with actix::test.

Please let me know what you think of this approach, and whether you have another suggestion!

@rubdos

Previously,

async fn foo(_a: u32) {}

would compile to

fn foo() {/* something */}

This patches changes this behaviour to

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

by simply forwarding the input arguments.

This allows any test fixture library (e.g. rstest, cfr. la10736/rstest#85) to integrate with actix::test.

rubdos added a commit to rubdos/rstest that referenced this pull request

Apr 8, 2020

@rubdos

This allows different crates (e.g. async_std, actix_rt, tokio) to integrate with rstest. After for example actix/actix-net#127, the combination rstest+actix will Just Work, through for example

fn logger() -> Logger {}

async fn foo(logger: Logger) {
}

rubdos added a commit to rubdos/rstest that referenced this pull request

Apr 8, 2020

@rubdos

This allows different crates (e.g. async_std, actix_rt, tokio) to integrate with rstest. After for example actix/actix-net#127, the combination rstest+actix will Just Work, through for example

fn logger() -> Logger {}

 #[actix_rt::test]
 #[rstest]
 #[test]
async fn foo(logger: Logger) {
}

@codecov

@rubdos

I notice coverage went down by 0.02%. If you want me to cover some more code, I can add a patch like this:

diff --git a/actix-macros/Cargo.toml b/actix-macros/Cargo.toml index eb72e52..e59dac1 100644 --- a/actix-macros/Cargo.toml +++ b/actix-macros/Cargo.toml @@ -19,3 +19,4 @@ syn = { version = "^1", features = ["full"] }

[dev-dependencies] actix-rt = { version = "1.0.0" } +rstest = "0.6" diff --git a/actix-macros/src/lib.rs b/actix-macros/src/lib.rs index ffd8147..86d448a 100644 --- a/actix-macros/src/lib.rs +++ b/actix-macros/src/lib.rs @@ -53,6 +53,18 @@ pub fn main(: TokenStream, item: TokenStream) -> TokenStream { /// assert!(true); /// } /// +/// +/// It also forwards arguments to tests, such that it works with fixture libraries. +/// +///no_run +/// use rstest::*; +/// +/// #[actix_rt::test] +/// #[rstest] +/// async fn my_test(fix: Fix) { +/// assert!(true); +/// } +/// ``` #[proc_macro_attribute] pub fn test(: TokenStream, item: TokenStream) -> TokenStream { let input = syn::parse_macro_input!(item as syn::ItemFn);

It does however require a fixture libary to "really" cover the new function.

JohnTitor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@JohnTitor

I notice coverage went down by 0.02%. If you want me to cover some more code, I can add a patch like this:

I'd like to ignore the coverage here.

@rubdos rubdos deleted the test-fixture-integration branch

April 9, 2020 08:48

2 participants

@rubdos @JohnTitor