Skip to content

Commit

Permalink
#160 Tests fixed and add unit for allow
Browse files Browse the repository at this point in the history
non_snake_case in fn
  • Loading branch information
la10736 committed Nov 27, 2022
1 parent 1405163 commit a302be0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
51 changes: 46 additions & 5 deletions rstest_macros/src/render/test.rs
Expand Up @@ -968,7 +968,8 @@ mod matrix_cases_should {
assert!(tests.len() > 0);

for t in tests {
assert_eq!(item_fn.attrs, &t.attrs[1..]);
let end = t.attrs.len() - 1;
assert_eq!(item_fn.attrs, &t.attrs[1..end]);
}
}

Expand Down Expand Up @@ -1067,6 +1068,7 @@ mod matrix_cases_should {
attributes: &str,
) {
let attributes = attrs(attributes);
let filter = attrs("#[allow(non_snake_case)]");
let data = RsTestData {
items: vec![values_list("v", &["1", "2", "3"]).into()].into(),
};
Expand All @@ -1082,7 +1084,12 @@ mod matrix_cases_should {
assert!(tests.len() > 0);

for test in tests {
assert_eq!(attributes, test.attrs);
let filterd: Vec<_> = test
.attrs
.into_iter()
.filter(|a| !filter.contains(a))
.collect();
assert_eq!(attributes, filterd);
}
}

Expand Down Expand Up @@ -1119,7 +1126,40 @@ mod matrix_cases_should {

for test in tests {
assert_eq!(test.attrs[0], test_attribute);
assert_eq!(&test.attrs[1..], attributes.as_slice());
assert_eq!(&test.attrs[1..test.attrs.len() - 1], attributes.as_slice());
}
}

#[rstest]
fn add_allow_non_snake_case(
#[values(
"",
"#[no_one]",
"#[should_panic]",
"#[should_panic]#[other]",
"#[a::b::c]#[should_panic]"
)]
attributes: &str,
) {
let attributes = attrs(attributes);
let non_snake_case = &attrs("#[allow(non_snake_case)]")[0];
let data = RsTestData {
items: vec![values_list("v", &["1", "2", "3"]).into()].into(),
};

let mut item_fn: ItemFn = r#"fn test(v: u32) {{ println!("user code") }}"#.ast();
item_fn.attrs = attributes.clone();

let tokens = matrix(item_fn, data.into());

let tests = TestsGroup::from(tokens).get_all_tests();

// Sanity check
assert!(tests.len() > 0);

for test in tests {
assert_eq!(test.attrs.last().unwrap(), non_snake_case);
assert_eq!(&test.attrs[1..test.attrs.len() - 1], attributes.as_slice());
}
}

Expand Down Expand Up @@ -1491,7 +1531,8 @@ mod complete_should {
let attrs = attrs("#[first]#[second(arg)]");

for f in modules[0].get_all_tests() {
assert_eq!(attrs, &f.attrs[1..]);
let end = f.attrs.len() - 1;
assert_eq!(attrs, &f.attrs[1..end]);
}
for f in modules[1].get_all_tests() {
assert_eq!(attrs, &f.attrs[1..3]);
Expand All @@ -1503,7 +1544,7 @@ mod complete_should {
let attrs = attrs("#[third]#[forth(other)]");

for f in modules[1].get_all_tests() {
assert_eq!(attrs, &f.attrs[3..]);
assert_eq!(attrs, &f.attrs[3..5]);
}
}
}
2 changes: 1 addition & 1 deletion rstest_macros/src/test.rs
Expand Up @@ -6,10 +6,10 @@
use std::borrow::Cow;
use std::iter::FromIterator;

pub(crate) use rstest::{fixture, rstest};
pub(crate) use pretty_assertions::assert_eq;
use proc_macro2::TokenTree;
use quote::quote;
pub(crate) use rstest::{fixture, rstest};
use syn::{parse::Parse, parse2, parse_str, Error, Expr, Ident, ItemFn, Stmt};

use super::*;
Expand Down

0 comments on commit a302be0

Please sign in to comment.