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

Append generated test macro so next test macros are aware of it #291

Merged
merged 1 commit into from
Jan 17, 2025
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Changed

- Append generated test macro so next test macros are aware of it (see [#291](https://github.com/la10736/rstest/pull/291)).

### Add

### Fix
Expand Down
2 changes: 1 addition & 1 deletion rstest_macros/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@ fn single_test_case(
let lifetimes = generics.lifetimes();

quote! {
#test_attr
#(#attrs)*
#test_attr
#asyncness fn #name<#(#lifetimes,)*>(#(#ignored_args,)*) #output {
#test_impl
#inject
Expand Down
35 changes: 19 additions & 16 deletions rstest_macros/src/render/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,9 @@ mod single_test_should {

let result: ItemFn = single(input_fn.clone(), Default::default()).ast();

assert_eq!(result.attrs[0], test_attribute);
assert_eq!(&result.attrs[1..], attributes.as_slice());
let (generated_attribute, old_attributes) = result.attrs.split_last().unwrap();
assert_eq!(old_attributes, attributes.as_slice());
assert_eq!(generated_attribute, &test_attribute);
}

#[rstest]
Expand Down Expand Up @@ -648,7 +649,7 @@ mod cases_should {
assert!(tests.len() > 0);

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

Expand All @@ -669,7 +670,8 @@ mod cases_should {

let tokens = parametrize(item_fn, info);

let test_attrs = &TestsGroup::from(tokens).get_all_tests()[0].attrs[1..];
let tests = TestsGroup::from(tokens).get_all_tests();
let test_attrs = tests[0].attrs.split_last().unwrap().1;

let l = given_attrs.len();

Expand Down Expand Up @@ -886,9 +888,10 @@ mod cases_should {
let tokens = parametrize(item_fn, info);

let tests = TestsGroup::from(tokens).get_all_tests();
let (generated_attribute, old_attributes) = tests[0].attrs.split_last().unwrap();

assert_eq!(tests[0].attrs[0], test_attribute);
assert_eq!(&tests[0].attrs[1..], attributes.as_slice());
assert_eq!(old_attributes, attributes.as_slice());
assert_eq!(generated_attribute, &test_attribute);
}

#[test]
Expand Down Expand Up @@ -1213,8 +1216,8 @@ mod matrix_cases_should {
assert!(tests.len() > 0);

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

Expand Down Expand Up @@ -1370,8 +1373,8 @@ mod matrix_cases_should {
assert!(tests.len() > 0);

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

Expand Down Expand Up @@ -1434,8 +1437,8 @@ mod matrix_cases_should {
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());
assert_eq!(&test.attrs[test.attrs.len() - 2], non_snake_case);
assert_eq!(&test.attrs[..test.attrs.len() - 2], attributes.as_slice());
}
}

Expand Down Expand Up @@ -1926,11 +1929,11 @@ mod complete_should {
let attrs = attrs("#[first]#[second(arg)]");

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

for f in modules[1].get_all_tests() {
assert_eq!(attrs, &f.attrs[3..5]);
assert_eq!(attrs, &f.attrs[2..4]);
}
}
}