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.

Closes #101.
  • Loading branch information
kezhuw committed Apr 19, 2024
1 parent 39526d4 commit c2573f8
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 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,10 @@ impl TestCase {
quote! { let _result = super::#item_name(#(#arg_values),*).await; },
)
} else {
attrs.insert(0, parse_quote! { #[::core::prelude::v1::test] });
let test_attr = parse_quote! { #[::core::prelude::v1::test] };
if !attrs.iter().any(|attr| *attr == test_attr) {
attrs.push(test_attr);
}
(
TokenStream2::new(),
quote! { let _result = super::#item_name(#(#arg_values),*); },
Expand Down

0 comments on commit c2573f8

Please sign in to comment.