Skip to content

Commit

Permalink
feat: retain allow attribute in test_case macro (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnPeel committed Jul 27, 2023
1 parent dfef0a8 commit dee411a
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 1 deletion.
7 changes: 6 additions & 1 deletion crates/test-case-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ fn render_test_cases(test_cases: &[(TestCase, Span2)], mut item: ItemFn) -> Toke
let mod_name = item.sig.ident.clone();

// We don't want any external crate to alter main fn code, we are passing attributes to each sub-function anyway
item.attrs.clear();
item.attrs.retain(|attr| {
attr.path
.get_ident()
.map(|ident| ident == "allow")
.unwrap_or(false)
});

let output = quote! {
#[allow(unused_attributes)]
Expand Down
14 changes: 14 additions & 0 deletions tests/acceptance_cases/allow_stays_on_fn/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "allow_stays_on_fn"
version = "0.1.0"
edition = "2021"

[lib]
name = "allow_stays_on_fn"
path = "src/lib.rs"
doctest = false

[dependencies]
test-case = { path = "../../../" }

[workspace]
7 changes: 7 additions & 0 deletions tests/acceptance_cases/allow_stays_on_fn/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![deny(unused_variables)]

use test_case::test_case;

#[test_case(42)]
#[allow(unused_variables)]
fn allow_stays_on_fn(value: u32) {}
5 changes: 5 additions & 0 deletions tests/acceptance_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,8 @@ fn cases_can_use_regex() {
fn features_produce_human_readable_errors() {
run_acceptance_test!("features_produce_human_readable_errors")
}

#[test]
fn allow_stays_on_fn() {
run_acceptance_test!("allow_stays_on_fn")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
source: tests/acceptance_tests.rs
expression: output
---
running 1 test
test allow_stays_on_fn::_42_expects ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
source: tests/acceptance_tests.rs
expression: output
---
running 1 test
test allow_stays_on_fn::_42_expects ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

0 comments on commit dee411a

Please sign in to comment.