From fb32f74f21ca7c19d26cb395270245d534534b2b Mon Sep 17 00:00:00 2001 From: Tom Parker-Shemilt Date: Sun, 21 Apr 2024 22:12:25 +0100 Subject: [PATCH] Standard test attribute worked with mod, others didn't This fixes things with any foo::test attribute --- serial_test_derive/src/lib.rs | 44 +++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/serial_test_derive/src/lib.rs b/serial_test_derive/src/lib.rs index d9465ea..2aa778e 100644 --- a/serial_test_derive/src/lib.rs +++ b/serial_test_derive/src/lib.rs @@ -342,10 +342,10 @@ fn core_setup( attr.meta .path() .segments - .first() - .unwrap() - .ident - .to_string() + .iter() + .map(|s| s.ident.to_string()) + .collect::>() + .join("::") .contains("test") }) => { @@ -739,4 +739,40 @@ mod tests { }; compare_streams(compare, stream); } + + #[test] + fn test_later_test_mod() { + init(); + let attrs = proc_macro2::TokenStream::new(); + let input = quote! { + #[cfg(test)] + #[serial] + mod serial_attr_tests { + pub fn foo() { + println!("Nothing"); + } + + #[demo_library::test] + fn bar() {} + } + }; + let stream = local_serial_core( + proc_macro2::TokenStream::from_iter(attrs.into_iter()), + input, + ); + let compare = quote! { + #[cfg(test)] + mod serial_attr_tests { + pub fn foo() { + println!("Nothing"); + } + + #[demo_library::test] + fn bar() { + serial_test::local_serial_core(vec![""], ::std::option::Option::None, || {} ); + } + } + }; + compare_streams(compare, stream); + } }