summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeb Rosen <jeb@jebrosen.com>2020-05-12 00:09:59 -0700
committerGitHub <noreply@github.com>2020-05-12 09:09:59 +0200
commit1cc016833569e2dbae3b0431b7c87d5e75ef5de6 (patch)
treeff416f97fc4f840161b9ae25b5a42c5d3deaab72
parent67220eac37b77abb29cab693083694686c487d5f (diff)
macros: disambiguate the built-in #[test] attribute in macro expansion (#2503)
`tokio::test` and related macros now use the absolute path `::core::prelude::v1::test` to refer to the built-in `test` macro. This absolute path was introduced in rust-lang/rust#62086.
-rw-r--r--tokio-macros/src/entry.rs6
-rw-r--r--tokio/tests/macros_test.rs19
2 files changed, 22 insertions, 3 deletions
diff --git a/tokio-macros/src/entry.rs b/tokio-macros/src/entry.rs
index 6a58b791..2681f50d 100644
--- a/tokio-macros/src/entry.rs
+++ b/tokio-macros/src/entry.rs
@@ -142,7 +142,7 @@ fn parse_knobs(
let header = {
if is_test {
quote! {
- #[test]
+ #[::core::prelude::v1::test]
}
} else {
quote! {}
@@ -334,14 +334,14 @@ pub(crate) mod old {
let result = match runtime {
Runtime::Threaded => quote! {
- #[test]
+ #[::core::prelude::v1::test]
#(#attrs)*
#vis fn #name() #ret {
tokio::runtime::Runtime::new().unwrap().block_on(async { #body })
}
},
Runtime::Basic | Runtime::Auto => quote! {
- #[test]
+ #[::core::prelude::v1::test]
#(#attrs)*
#vis fn #name() #ret {
tokio::runtime::Builder::new()
diff --git a/tokio/tests/macros_test.rs b/tokio/tests/macros_test.rs
new file mode 100644
index 00000000..8e68b8a4
--- /dev/null
+++ b/tokio/tests/macros_test.rs
@@ -0,0 +1,19 @@
+use tokio::test;
+
+#[test]
+async fn test_macro_can_be_used_via_use() {
+ tokio::spawn(async {
+ assert_eq!(1 + 1, 2);
+ })
+ .await
+ .unwrap();
+}
+
+#[tokio::test]
+async fn test_macro_is_resilient_to_shadowing() {
+ tokio::spawn(async {
+ assert_eq!(1 + 1, 2);
+ })
+ .await
+ .unwrap();
+}