From 60eee70fbd0514f1f987b75d5e605aa22d4debff Mon Sep 17 00:00:00 2001 From: bl-ue <54780737+bl-ue@users.noreply.github.com> Date: Wed, 7 Dec 2022 16:48:55 -0700 Subject: [PATCH 1/2] Pass the function's visibilty to the generated function Closes #80 --- serial_test_derive/src/lib.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/serial_test_derive/src/lib.rs b/serial_test_derive/src/lib.rs index 47dfcdd..1caaed7 100644 --- a/serial_test_derive/src/lib.rs +++ b/serial_test_derive/src/lib.rs @@ -377,6 +377,7 @@ where if asyncness.is_some() && cfg!(not(feature = "async")) { panic!("async testing attempted with async feature disabled in serial_test!"); } + let vis = ast.vis; let name = ast.sig.ident; let return_type = match ast.sig.output { syn::ReturnType::Default => None, @@ -414,7 +415,7 @@ where quote! { #(#attrs) * - async fn #name () -> #ret { + #vis async fn #name () -> #ret { serial_test::#fnname(#(#args ),*, || async #block ).await; } } @@ -424,7 +425,7 @@ where quote! { #(#attrs) * - fn #name () -> #ret { + #vis fn #name () -> #ret { serial_test::#fnname(#(#args ),*, || #block ) } } @@ -437,7 +438,7 @@ where quote! { #(#attrs) * - async fn #name () { + #vis async fn #name () { serial_test::#fnname(#(#args ),*, || async #block ).await; } } @@ -447,7 +448,7 @@ where quote! { #(#attrs) * - fn #name () { + #vis fn #name () { serial_test::#fnname(#(#args ),*, || #block ); } } From 467b02f4238d313027c5f1e2130c3e18fb3d06a3 Mon Sep 17 00:00:00 2001 From: bl-ue <54780737+bl-ue@users.noreply.github.com> Date: Wed, 7 Dec 2022 17:23:28 -0700 Subject: [PATCH 2/2] Add a test for #[serial] + pub fn --- serial_test_derive/src/lib.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/serial_test_derive/src/lib.rs b/serial_test_derive/src/lib.rs index 1caaed7..c8773e2 100644 --- a/serial_test_derive/src/lib.rs +++ b/serial_test_derive/src/lib.rs @@ -503,6 +503,23 @@ mod tests { assert_eq!(format!("{}", compare), format!("{}", stream)); } + #[test] + fn test_serial_with_pub() { + let attrs = proc_macro2::TokenStream::new(); + let input = quote! { + #[test] + pub fn foo() {} + }; + let stream = local_serial_core(attrs.into(), input); + let compare = quote! { + #[test] + pub fn foo () { + serial_test::local_serial_core("", :: std :: option :: Option :: None, || {} ); + } + }; + assert_eq!(format!("{}", compare), format!("{}", stream)); + } + #[test] fn test_serial_with_timeout() { let attrs = vec![