Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions assay-proc-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use syn::{
struct AssayAttribute {
include: Option<Vec<String>>,
should_panic: bool,
ignore: bool,
env: Option<Vec<(String, String)>>,
setup: Option<Expr>,
teardown: Option<Expr>,
Expand All @@ -25,6 +26,7 @@ impl Parse for AssayAttribute {
fn parse(input: ParseStream) -> Result<Self> {
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;
Expand Down Expand Up @@ -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()?;
Expand Down Expand Up @@ -97,6 +100,7 @@ impl Parse for AssayAttribute {
Ok(AssayAttribute {
include,
should_panic,
ignore,
env,
setup,
teardown,
Expand Down Expand Up @@ -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 {
Expand All @@ -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();
Expand All @@ -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) {}

Expand Down
11 changes: 11 additions & 0 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}