diff --git a/assay-proc-macro/src/lib.rs b/assay-proc-macro/src/lib.rs index 917fed8..775be15 100644 --- a/assay-proc-macro/src/lib.rs +++ b/assay-proc-macro/src/lib.rs @@ -16,6 +16,7 @@ use syn::{ struct AssayAttribute { include: Option>, should_panic: bool, + ignore: bool, env: Option>, setup: Option, teardown: Option, @@ -25,6 +26,7 @@ impl Parse for AssayAttribute { fn parse(input: ParseStream) -> Result { let mut include = None; let mut should_panic = false; + let mut ignore = false; let mut env = None; let mut setup = None; let mut teardown = None; @@ -55,6 +57,7 @@ impl Parse for AssayAttribute { ); } "should_panic" => should_panic = true, + "ignore" => ignore = true, "env" => { let _: Token![=] = input.parse()?; let array: ExprArray = input.parse()?; @@ -97,6 +100,7 @@ impl Parse for AssayAttribute { Ok(AssayAttribute { include, should_panic, + ignore, env, setup, teardown, @@ -131,6 +135,12 @@ pub fn assay(attr: TokenStream, item: TokenStream) -> TokenStream { quote! {} }; + let ignore = if attr.ignore { + quote! { #[ignore] } + } else { + quote! {} + }; + let env = if let Some(env) = attr.env { let mut out = quote! {}; for (k, v) in env { @@ -155,6 +165,7 @@ pub fn assay(attr: TokenStream, item: TokenStream) -> TokenStream { // Parse the function out into individual parts let func = parse_macro_input!(item as ItemFn); + let attrs = func.attrs; let vis = func.vis; let mut sig = func.sig; let name = sig.ident.clone(); @@ -177,6 +188,8 @@ pub fn assay(attr: TokenStream, item: TokenStream) -> TokenStream { let expanded = quote! { #[test] #should_panic + #ignore + #(#attrs)* #vis #sig { fn modify(_: &mut std::process::Command) {} diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index bc5b1de..e0db535 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -160,3 +160,14 @@ impl Future for ReadyOnPoll { Poll::Ready(()) } } + +#[assay(ignore)] +fn should_be_ignored() { + panic!("this test should be ignored") +} + +#[assay] +#[should_panic] +fn respects_other_attributes() { + panic!("this test is expected to panic"); +}