Define the property function in the original scope. This is to support adding regression test in the same scope calling the property function. PiperOrigin-RevId: 982093389
diff --git a/rust/fuzztest_macro/src/lib.rs b/rust/fuzztest_macro/src/lib.rs index 12f164e..d51935a 100644 --- a/rust/fuzztest_macro/src/lib.rs +++ b/rust/fuzztest_macro/src/lib.rs
@@ -64,7 +64,7 @@ pub fn fuzztest(args: TokenStream, input: TokenStream) -> TokenStream { let item = parse_macro_input!(input as Item); - let syn::Item::Fn(mut test_fn) = item else { + let syn::Item::Fn(test_fn) = item else { return syn::Error::new_spanned(item, "not a function").into_compile_error().into(); }; @@ -102,18 +102,21 @@ Err(e) => return e.into_compile_error().into(), }; - test_fn.sig.ident = fuzztest_registration_context.prop_fn_ident().clone(); + let prop_fn_ident = fuzztest_registration_context.prop_fn_ident().clone(); let fuzztest_mod_name = quote::format_ident!("__fuzztest_mod__{}", original_ident); // TODO(mathuxny-73): Extract the current module path from the invocation of the macro // (ie: from `item.attrs`) let tokens = quote! { + + #test_fn + #[allow(non_snake_case)] mod #fuzztest_mod_name { use super::*; - #test_fn + use super::#original_ident as #prop_fn_ident; #fuzztest_object_tokenstream
diff --git a/rust/tests/macro_compiles.rs b/rust/tests/macro_compiles.rs index 5eee104..04c245e 100644 --- a/rust/tests/macro_compiles.rs +++ b/rust/tests/macro_compiles.rs
@@ -26,4 +26,8 @@ #[fuzztest(_a = VecOf::new(Arbitrary::<i32>::default()).with_max_len(10))] fn fuzztest_macro_compiles_with_vec(_a: Vec<i32>) {} -fn main() {} +fn main() { + // The property function is defined in the scope where the macro is + // invoked, so it can be called directly, e.g. from a regression test. + fuzztest_macro_compiles(0); +}