-
Notifications
You must be signed in to change notification settings - Fork 39
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
fix: improve compatibility among test proc macros #143
base: master
Are you sure you want to change the base?
Conversation
This pr proposes a generic mechanism among different test proc macros to avoid to generate multiple `[::core::prelude::v1::test]` on test method. `proc_macro_attribute` function is fed with tokens after its attribute and no tokens before it. Give the above, this pr proposes test proc macros to append newly generated macros after existing ones. This way, proc macros processed later can read all macros including generated and handwritten and make further decisions. Specifically, proc macros can append `#[::core::prelude::v1::test]` only if it does not exist. Macros that transform test method signature can append `#[::core::prelude::v1::test]` directly without checking its existence once they generate valid signature for test method. Closes frondeus#101.
This comes from my experience in kezhuw/stuck#51. Currently, above tests are run twice each as both I worked out a solution not only for One can take kezhuw/stuck#53 as an example for how it solve this. It depends on patch from this pr. @frondeus @d-e-s-o @taiki-e @Darksonn Sorry for ping you, but would you mind take a look at this and check whether we have a chance to solve this in general ? |
So, to sum up, your proposal is that test macros should add |
Yeh, that is it. And I think |
@tamird expressed similar in d-e-s-o/test-log#35
I think it is also encouraged for decoration test macros to not generate any form of To be simple, test proc macros should choose either of two.
Hopefully, we can solve this without breaking changes. |
c2573f8
to
2099742
Compare
Added a fixup commit to error duplicated test attributes which is similar to |
This way if preceding test macros add `#[::core::prelude::v1::test]` by appending, then we can avoid duplicated test runs. See also frondeus/test-case#101, frondeus/test-case#143 Closes d-e-s-o#35.
Co-authored-by: Alice Ryhl <[email protected]>
Hi @frondeus, would you mind take a look at this ? It solves #101. I have synced this with tokio counterpart tokio-rs/tokio#6497. |
@@ -110,7 +110,7 @@ fn expand_additional_test_case_macros(item: &mut ItemFn) -> syn::Result<Vec<(Tes | |||
} | |||
|
|||
for i in attrs_to_remove.into_iter().rev() { | |||
item.attrs.swap_remove(i); | |||
item.attrs.remove(i); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This preserve order or attributes.
This pr proposes a generic mechanism among different test proc macros to avoid to generate multiple
[::core::prelude::v1::test]
on test method.proc_macro_attribute
function is fed with tokens after its attribute and no tokens before it.Give the above, this pr proposes test proc macros to append newly generated macros after existing ones. This way, proc macros processed later can read all macros including generated and handwritten and make further decisions. Specifically, proc macros can append
#[::core::prelude::v1::test]
only if it does not exist.Macros that transform test method signature can append
#[::core::prelude::v1::test]
directly without checking its existence once they generate valid signature for test method.Closes #101.