-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
macros: append generated test attribute so others are aware of it #6497
macros: append generated test attribute so others are aware of it #6497
Conversation
This way other test macros can choose to not generate `#[::core::prelude::v1::test]` to avoid duplicated test runs. This commit also rejects existing `#[::core::prelude::v1::test]` just like how and why it rejects existing `#[test]`.
tokio-macros/Cargo.toml
Outdated
@@ -24,7 +24,7 @@ proc-macro = true | |||
[dependencies] | |||
proc-macro2 = "1.0.60" | |||
quote = "1" | |||
syn = { version = "2.0", features = ["full"] } | |||
syn = { version = "2.0", features = ["full", "extra-traits"] } |
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.
What do you need this feature for? I prefer to avoid adding these features as they hurt compilation times.
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.
impl PartialEq for Attribute
. I guess I could duplicate code. Let me figure out.
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 see. if it is possible, then try to perform the equality check manually. Thanks!
error: second test attribute is supplied, try to order it after `tokio::test` | ||
--> $DIR/macros_invalid_input.rs:49:1 | ||
| | ||
49 | #[::core::prelude::v1::test::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.
What? The #[tokio::test]
macro is first, so what do you mean by "after"?
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 supposed this to be generated by other preceding test macros, e.g. #[test_log::test]
. I guess I should reshape it or keep it origin. Any preference ?
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.
How about "second test attribute is supplied, consider removing or ordering it after tokio::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.
My challenge with the wording here is that the code that triggers this error has #[tokio::test]
first, and then afterwards, it has a #[::core::prelude::v1::test]
. So suggesting that you move #[::core::prelude::v1::test]
after #[tokio::test]
doesn't make since it's already after #[tokio::test]
. Perhaps you could say "before" or "above" instead of "after"?
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 know, it is strange. It should be something similar to following.
❯ grep -n -B 2 -A 2 "with_append_test_attribute_and_test_args_and_panic_async" tests/mod.rs
84-#[test_log::test]
85-#[tokio::test]
86:async fn with_append_test_attribute_and_test_args_and_panic_async(x: i8, _y: i8) {
87- assert_eq!(x, 0);
88-}
❯
❯ cargo test with_append_test_attribute_and_test_args_and_panic_async -- --nocapture
error: second test attribute is supplied, consider removing it or ordering it after `tokio::test`
--> tests/mod.rs:84:1
|
84 | #[test_log::test]
| ^^^^^^^^^^^^^^^^^
|
= note: this error originates in the attribute macro `test_log::test` (in Nightly builds, run with -Z macro-backtrace for more info)
error: could not compile `test-log` (test "mod") due to 2 previous errors
Moving it "before" or "above" will result in duplicated test runs.
I guess we could:
- Introduce dev dependency
test-log
. This ways the words should be more intuitively. Is it worth ? - Use the short version "second test attribute is supplied".
- Other suggestions.
Hi @Darksonn, thank you for reviewing. I have updated this with a fixup commit targeting to your two concerns. Regarding the error words, I am open to any sentence, simply not good at 😮💨 .
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.
Maybe just say "consider removing or changing the order of your test attributes".
…s are aware of it
…o others are aware of it
Hi @Darksonn, thank you for your reviewing, I have solved all review comments. Is there anything else left for this to move forward ? Should I do some squash/rebase work ? |
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.
Hi again, thanks for the ping. Sorry about the delay.
tokio-macros/src/entry.rs
Outdated
syn::Meta::Path(path) => path, | ||
_ => return false, | ||
}; | ||
let segments = ["core", "prelude", "v1", "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.
It's also available as a few other paths such as ::std::prelude::v1::test
and ::core::prelude::rust_2021::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.
Would this be too paranoid for us ?
Given that Rust has three editions since v1
and new coming in future, together with combinations from "std", "core" and leading colon, this is a pretty large list.
Given the fact that test
is there since day one, I would recommend not doing this. I checked test macros listed below and none use variants other than the two. I don't think test macros should generate other variants, if they do, let them fix it to avoid duplicated test runs but not us.
- test-log, test-case, async-std::test, googletest::test uses
::core::prelude::v1::test
. - quickcheck, test-strategy, rstest uses
#[test]
proptest
,tracing_test::traced_test does not generate any
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.
Perhaps we can match ::[std|core]::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.
Updated. Additionally, leading colons are optional now as review comments below.
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. If you can also add some of the variants to the tests, then I think this is ready to merge.
#[tokio::test] | ||
#[::core::prelude::v1::test] | ||
async fn test_has_generated_second_test_attr() {} |
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.
What about core without the leading colons?
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.
Thank you.
We decided to bump minimum required version of tokio to 1.34. Currently, the newest tokio version is 1.38, but some of the integration tests are eaten when testing with this specific verstion of tokio. Which is why, as of now, we decided not to support this version. The issue with version 1.38 is related to #[tokio::test] and #[ntest::timeout] attributes. Refs: - tokio-rs/tokio#6610 - becheran/ntest#28 - tokio-rs/tokio#6497
We decided to bump minimum required version of tokio to 1.34. Currently, the newest tokio version is 1.38, but some of the integration tests are eaten when testing with this specific verstion of tokio. Which is why, as of now, we decided not to support this version. The issue with version 1.38 is related to #[tokio::test] and #[ntest::timeout] attributes. Refs: - tokio-rs/tokio#6610 - becheran/ntest#28 - tokio-rs/tokio#6497
We decided to bump minimum required version of tokio to 1.34. Currently, the newest tokio version is 1.38, but some of the integration tests are eaten when testing with this specific verstion of tokio. Which is why, as of now, we decided not to support this version. The issue with version 1.38 is related to #[tokio::test] and #[ntest::timeout] attributes. Refs: - tokio-rs/tokio#6610 - becheran/ntest#28 - tokio-rs/tokio#6497
We decided to bump minimum required version of tokio to 1.34. Currently, the newest tokio version is 1.38, but some of the integration tests are eaten when testing with this specific verstion of tokio. Which is why, as of now, we decided not to support this version. The issue with version 1.38 is related to #[tokio::test] and #[ntest::timeout] attributes. Refs: - tokio-rs/tokio#6610 - becheran/ntest#28 - tokio-rs/tokio#6497
Motivation
Improve compatibility among multiple test proc macros.
Solution
#[::core::prelude::v1::test]
to the end of test proc macros. This way, proc macros process later can choose to not generate#[::core::prelude::v1::test]
to avoid duplicated test runs.#[::core::prelude::v1::test]
to avoid duplicated test runs astokio::test
is transforming an invalid test signature to one accepted by#[test]
. This is consistent with what we currently treat#[test]
.Links