Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass the function's visibilty to the generated function #81

Merged
merged 2 commits into from Dec 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 22 additions & 4 deletions serial_test_derive/src/lib.rs
Expand Up @@ -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,
Expand Down Expand Up @@ -414,7 +415,7 @@ where
quote! {
#(#attrs)
*
async fn #name () -> #ret {
#vis async fn #name () -> #ret {
serial_test::#fnname(#(#args ),*, || async #block ).await;
}
}
Expand All @@ -424,7 +425,7 @@ where
quote! {
#(#attrs)
*
fn #name () -> #ret {
#vis fn #name () -> #ret {
serial_test::#fnname(#(#args ),*, || #block )
}
}
Expand All @@ -437,7 +438,7 @@ where
quote! {
#(#attrs)
*
async fn #name () {
#vis async fn #name () {
serial_test::#fnname(#(#args ),*, || async #block ).await;
}
}
Expand All @@ -447,7 +448,7 @@ where
quote! {
#(#attrs)
*
fn #name () {
#vis fn #name () {
serial_test::#fnname(#(#args ),*, || #block );
}
}
Expand Down Expand Up @@ -502,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![
Expand Down