Skip to content

Commit

Permalink
fix: improve compatibility among test proc macros
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kezhuw committed Apr 17, 2024
1 parent 39526d4 commit 2099742
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion crates/test-case-core/src/test_case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl TestCase {
quote! { let _result = super::#item_name(#(#arg_values),*).await; },
)
} else {
attrs.insert(0, parse_quote! { #[::core::prelude::v1::test] });
attrs.push(parse_quote! { #[::core::prelude::v1::test] });
(
TokenStream2::new(),
quote! { let _result = super::#item_name(#(#arg_values),*); },
Expand Down

0 comments on commit 2099742

Please sign in to comment.