-
Notifications
You must be signed in to change notification settings - Fork 37
Append #[::core::prelude::v1::test] only if no test macros exist #46
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
Conversation
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.
Thanks for the proposal! I am fine with the approach. Left a few nitpicks.
This pr depends on frondeus/test-case#143 and tokio-rs/tokio#6497.
Can we please wait until these are merged? I'd rather not include any temporary patches.
@d-e-s-o Thank you for reviewing. I am good with the merge timing. I have pushed with a fixup commit to solve your concerns. Also, I checked that there is no duplicated test runs for new test cases. |
It seems as if the |
Do you mean tests like this ? #[test_log::test(test_case::test_case(-2, -4; "my test name"))]
fn with_inner_test_attribute_and_test_args_and_name(x: i8, y: i8) {
assert_eq!(x, -2);
assert_eq!(y, -4);
} This pr does not depend on this. I can drop some tests so that we don't need to patch |
Those tests should pass once frondeus/test-case#143 published. Or I could |
Right, I understand it's just a development thing and all that, but my point is that we don't want to loose the coverage nor do we want to depend on some unpublished snapshot (or add So the easiest way out that I can think of would be to just use some other proc macro that supports more or less arbitrary syntax in |
For test coverage, the following two methods are identical in #[tokio::test]
#[test_log::test]
async fn with_append_test_attribute_and_async() {
assert_eq!(async { 42 }.await, 42)
}
#[test_case::test_case(-2, -4)]
#[test_case::test_case(-2, -5)]
#[test_log::test]
fn with_append_test_attribute_and_test_args(x: i8, _y: i8) {
assert_eq!(x, -2);
}
Let me figure out. |
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.
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.
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.
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.
`#[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.
`#[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 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. Without the fix, the new test will run twice. See also tokio-rs/tokio#6497, d-e-s-o/test-log#46, frondeus/test-case#143, la10736/rstest#291, google/googletest-rust#561, kezhuw/stuck#53.
628dff9
to
fb4f8d8
Compare
#[::core::prelude::v1::test]
only if it does not existfb4f8d8
to
1ffb4ee
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.
I think this looks great, thanks! Left a few more comments. Your initial PR description mentioned that we depend on frondeus/test-case#143. Why is that no longer the case? Unfortunately somehow GitHub seems to have managed to loose the original set of changes... :-(
macros/src/lib.rs
Outdated
const CANDIDATES_LEN: usize = 4; | ||
|
||
let candidates: [[&str; CANDIDATES_LEN]; 2] = [ | ||
["core", "prelude", "*", "test"], | ||
["std", "prelude", "*", "test"], | ||
]; |
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.
Can we go with the slightly simpler version you used here?
tests/mod.rs
Outdated
#[case(-3, -4)] | ||
#[test_log::test] | ||
// Applied to all cases, must not before `rstest`, see https://github.com/la10736/rstest/issues/210 | ||
#[should_panic] // https://docs.rs/rstest/latest/rstest/attr.rstest.html#use-specific-case-attributes |
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.
Let's use versioned URLs for the sake of persistence? https://docs.rs/rstest/0.25.0/rstest/attr.rstest.html#use-specific-case-attributes
tests/mod.rs
Outdated
#[case(-2, -4)] | ||
#[case(-3, -4)] | ||
#[test_log::test] | ||
// Applied to all cases, must not before `rstest`, see https://github.com/la10736/rstest/issues/210 |
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.
// Applied to all cases, must not before `rstest`, see https://github.com/la10736/rstest/issues/210 | |
// Applied to all cases, must not come before `rstest`, see https://github.com/la10736/rstest/issues/210 |
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.
Same below.
tests/mod.rs
Outdated
use tracing::debug; | ||
use tracing::error; | ||
use tracing::info; | ||
use tracing::instrument; | ||
|
||
|
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.
Nit: Let's keep spurious changes to a minimum?
I suspect it's because you added additional |
Here is the no rebased branch: https://github.com/d-e-s-o/test-log/commits/628dff9c4e0ea63c7e97d7f622e3ac89129169bf/ I think we are here because of #46 (comment). |
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.
Looks good to me. Feel free to squash the fixup commit and then we can get it in. Thanks again for your work.
This way we could avoid duplicated test runs if `#[test]` variants already exist See also frondeus/test-case#101, frondeus/test-case#143 and tokio-rs/tokio#6497. Closes d-e-s-o#35.
c45420f
to
c6ccb6c
Compare
Squashed. @d-e-s-o Thank you for reviewing! |
Add a CHANGELOG entry for pull request #46, which improved cooperation with other procedural macros also using #[test] attributes in some way and allowing them to be stacked.
With pull request #46 merged, we now have better support for stacking other #[test] attributes on top of ours. Document that better.
With pull request #46 merged, we now have better support for stacking other #[test] attributes on top of ours. Document that better.
This way we could avoid duplicated test runs if
#[test]
variants already existSee also frondeus/test-case#101, frondeus/test-case#143 and tokio-rs/tokio#6497.
Closes #35.