Skip to content
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 and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add capability to ignore arguments #228

Open
edward-shen opened this issue Jan 29, 2024 · 3 comments
Open

Add capability to ignore arguments #228

edward-shen opened this issue Jan 29, 2024 · 3 comments

Comments

@edward-shen
Copy link

Hey!

We have a macro that passes in a value to our tests, e.g.

#[company::test]
async fn(init_token: InitToken) { /* ... */ }

Normally, we could just generate a fixture, but the problem is that construction of this init token is unsafe. This results in a lot of libraries/binaries with an unsafe fixture just for this:

fn init_token() -> InitToken {
    unsafe { InitToken::do_dangerous() }
}

#[rstest]
#[company::test]
async fn(init_token: InitToken, my_arg: &str) { /* ... */ }

I was wondering if it was possible to support the ability to ignore certain parameters, something like this:

#[rstest]
#[company::test]
async fn(#[rstest::ignore] init_token: InitToken, my_arg: &str) { /* ... */ }

so that our macro could safely construct this token and pass that value in.

Thanks!

@la10736
Copy link
Owner

la10736 commented Jan 30, 2024

Could be a good idea but I prefer to use just #[ignore] instead. Anyway I've no time to implement it: any PR will be welcomed. I can point you to the right direction.... should be simple.

@edward-shen
Copy link
Author

Sure! I can try to take a look. Where would you suggest?

@la10736
Copy link
Owner

la10736 commented Feb 1, 2024

There are two steps:

  1. Parsing : where you extract the #[ignore] attributes and store a flag
  2. Rendering : where you should filter out the ignored arguments from the ones that are injected with value or fixture call.

ArgumentInfo

pub(crate) struct ArgumentInfo {

is the struct where we can add a ignore flag and we can implement a is_ignore() method in ArgumentsInfo
impl ArgumentsInfo {

For parsing stage you can take a look to rstest_macros::parse::future module to see how to implement and test it.

For rendering should be enough filter out the ignored arguments in

let inject = inject::resolve_aruments(args.iter(), &resolver, generic_types);

Maybe the hardest part is to find a way to write an end to end test.... I've no idea.

Please remember to add a changelog line and document the new feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants