14
14
15
15
use quote:: quote;
16
16
use syn:: {
17
- parse_macro_input, punctuated:: Punctuated , spanned:: Spanned , Attribute , DeriveInput , Expr ,
18
- ExprLit , FnArg , ItemFn , Lit , MetaNameValue , PatType , ReturnType , Signature , Type ,
17
+ parse_macro_input, parse_quote, punctuated:: Punctuated , spanned:: Spanned , Attribute ,
18
+ DeriveInput , Expr , ExprLit , FnArg , ItemFn , Lit , MetaNameValue , PatType , ReturnType , Signature ,
19
+ Type ,
19
20
} ;
20
21
21
22
/// Marks a test to be run by the Google Rust test runner.
@@ -75,7 +76,7 @@ pub fn gtest(
75
76
_args : proc_macro:: TokenStream ,
76
77
input : proc_macro:: TokenStream ,
77
78
) -> proc_macro:: TokenStream {
78
- let ItemFn { attrs, sig, block, .. } = parse_macro_input ! ( input as ItemFn ) ;
79
+ let ItemFn { mut attrs, sig, block, .. } = parse_macro_input ! ( input as ItemFn ) ;
79
80
let test_case_hash: u64 = {
80
81
use std:: collections:: hash_map:: DefaultHasher ;
81
82
use std:: hash:: { Hash , Hasher } ;
@@ -185,6 +186,12 @@ pub fn gtest(
185
186
)
186
187
}
187
188
} ;
189
+ if !attrs. iter ( ) . any ( is_test_attribute) && !is_rstest_enabled {
190
+ let test_attr: Attribute = parse_quote ! {
191
+ #[ :: core:: prelude:: v1:: test]
192
+ } ;
193
+ attrs. push ( test_attr) ;
194
+ } ;
188
195
let function = quote ! {
189
196
#( #attrs) *
190
197
#outer_sig -> #outer_return_type {
@@ -200,17 +207,7 @@ pub fn gtest(
200
207
#trailer
201
208
}
202
209
} ;
203
-
204
- let output = if attrs. iter ( ) . any ( is_test_attribute) || is_rstest_enabled {
205
- function
206
- } else {
207
- quote ! {
208
- #[ :: core:: prelude:: v1:: test]
209
- #function
210
- }
211
- } ;
212
-
213
- output. into ( )
210
+ function. into ( )
214
211
}
215
212
216
213
/// Extract the optional "expected" string literal from a `should_panic`
0 commit comments