-
Notifications
You must be signed in to change notification settings - Fork 47
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
Conversation
Ok the issue here is another: So, in this case you can work around to it with something like follow: pub mod google {
pub use gtest as test;
}
#[rstest]
#[case(1)]
#[google::test]
fn paramterised_test_should_work_with_rstest_first(#[case] value: u32) -> Result<()> {
verify_that!(value, eq(value))
} |
googletest did this already, it has The motivation from my side is to ease users of libraries. Attribute macros can only see macros following them. If we are going to generate macros in-place, then we will encounter this again for By conforming to rules:
Then, we resolve the problem in libraries but not spread it to users of libraries. |
Suddenly that is false 😢 ... And the sad part is that there isn't any no hacking way to identify what is previous and what is after: you can just try to guess it by code info in |
That's what https://docs.rs/rstest/latest/rstest/attr.rstest.html#inject-test-attribute |
Yeh, that is great. This pr completes the second part.
I am not sure what have you experienced. May be we have some misunderstandings here. But from what I known(rust-lang/rust#67839 (comment), rust-lang/rust#82419), ItemFn.attrs is attribute macros following the processing macro. From my understanding(might be wrong though), procedure of test macro never see preceding macros. Take the following code as an example. #[rstest]
#[gtest]
fn rstest_with_googletest() -> Result<()> {
verify_that!(1, eq(1))
} After #[test]
#[gtest]
fn rstest_with_googletest() -> Result<()> {
verify_that!(1, eq(1))
}
|
Ok, is little bit wired and is not simple to catch because normally you are thinking in terms of custom attributes, but I dumped the attributes received by custom procedural macro #[ignore]
/// Doc comment before
/* Multi line
comment */
// Simple comment before
#[attr_before::inspect_attrs(some)]
// Simple comment
/// Doc comment
#[ignore]
#[after]
fn ignore_attr() {
println!("done");
}
As you can see all 5 attribute are received |
You are right but... not all attributes are macros 😢 |
Anyway, I'm not against your PR (beside that's braking some tests 😄 ) ... I'm just a little bit scared because that's a breaking change. and in general rstest is trying to solve it with the convention that I mentioned before and and the possibility to ignore some arguments in order to have a better compatibility with other macros. |
Do you means "That's what rstest do when recognize a test attribute with that rule that I wrote before" ? If it is, this pr does not change this, actually depends on this.
Let me figure out what it breaks. And let's see whether it matters. |
28e20ea
to
e3045e4
Compare
Seems that the test fails due to some concurrent issues in test setup. It passed on my fork with 2 runs (https://github.com/kezhuw/rstest/actions/runs/12812929918/job/35727841633). I saw similar failure in https://github.com/la10736/rstest/actions/runs/12177266364/job/33964724311. |
I read some codes and think |
You are right, it's a well know issue. It's quite impossible to solve it without make the CI slower (de facto removing parallelism). This happen only on really slow machine like github runners but I was never able to reproduce it on my laptops. The issue is that the test use a workspace to generate the projects for the acceptance tests and sharing the compiled dependencies, so in this context a test can modify a workspace crate while another one read the same crate to compile its project. While I'm writing this I was thinking that a way could be save the workspace |
When I say that's a breaking change I mean that some users can leverage on that order, but never mind I don't think that's a really issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, Just add a line in chengelog please.
This way test macros following `#[rstest]` can decide whether or not to generate test macro to avoid duplicate test runs. It is an attempt to improve capabilities among test macros. Currently, following test from [googletest](https://github.com/google/googletest-rust/blob/21f2948684847922a416252b8118e3eada8e29d6/integration_tests/src/google_test_with_rstest.rs#L52-L57)(`main` branch at 2025-01-16) will run twice. ```rust #[rstest] #[case(1)] #[gtest] fn paramterised_test_should_work_with_rstest_first(#[case] value: u32) -> Result<()> { verify_that!(value, eq(value)) } ``` See: tokio-rs/tokio#6497, d-e-s-o/test-log#46, frondeus/test-case#143, kezhuw/stuck#53. Refs: rust-lang/rust#67839, rust-lang/rust#82419.
e3045e4
to
9937853
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!!!
Thank!!!!
`#[gtest]` will benefit from la10736/rstest#291, we could also benefit other test macros. It is an attempt to improve capabilities among test macros to avoid duplicated test runs which is rare to be aware of. The rationale is simple: procedure of attribute macro see only attributes following it. Macros next to processing macro will not see generated macro if it is generated in-place. So, instead of generating test macro in-place, appending generated test macro will let macros next to processing macro have chance to react, for example, not generate test macro if there is already one. We could deprecate `#[googletest::test]` oneday after rust-lang/rust#82419 released. See: tokio-rs/tokio#6497, d-e-s-o/test-log#46, frondeus/test-case#143, la10736/rstest#291, kezhuw/stuck#53. Refs: rust-lang/rust#67839, rust-lang/rust#82419.
`#[gtest]` will benefit from la10736/rstest#291, we could also benefit other test macros. It is an attempt to improve capabilities among test macros to avoid duplicated test runs which is rare to be aware of. The rationale is simple: procedure of attribute macro see only attributes following it. Macros next to processing macro will not see generated macro if it is generated in-place. So, instead of generating test macro in-place, appending generated test macro will let macros next to processing macro have chance to react, for example, not generate test macro if there is already one. We could deprecate `#[googletest::test]` oneday after la10736/rstest#291 released. See: tokio-rs/tokio#6497, d-e-s-o/test-log#46, frondeus/test-case#143, la10736/rstest#291, kezhuw/stuck#53. Refs: rust-lang/rust#67839, rust-lang/rust#82419.
`#[gtest]` will benefit from la10736/rstest#291, we could also benefit other test macros. This is an attempt to improve capabilities among test macros to avoid duplicated test runs which is rare to be aware of. The rationale is simple: procedure of attribute macro see only attributes following it. Macros next to processing macro will not see generated macro if it is generated in-place. So, instead of generating test macro in-place, appending generated test macro will let macros next to processing macro have chance to react, for example, not generate test macro if there is already one. We could deprecate `#[googletest::test]` oneday after la10736/rstest#291 released. See: tokio-rs/tokio#6497, d-e-s-o/test-log#46, frondeus/test-case#143, la10736/rstest#291, kezhuw/stuck#53. Refs: rust-lang/rust#67839, rust-lang/rust#82419.
This way test macros following
#[rstest]
can decide whether or not to generate test macro to avoid duplicate test runs.It is an attempt to improve capabilities among test macros. Currently, following test from googletest(
main
branch at 2025-01-16) will run twice.See: tokio-rs/tokio#6497, d-e-s-o/test-log#46, frondeus/test-case#143, kezhuw/stuck#53.
Refs: rust-lang/rust#67839, rust-lang/rust#82419.