Skip to content

Commit

Permalink
macros: Disambiguate the built-in #[test] attribute in macro expansion.
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
jebrosen committed May 11, 2020
1 parent 3ba818a commit a7e6771
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 3 additions & 3 deletions tokio-macros/src/entry.rs
Expand Up @@ -142,7 +142,7 @@ fn parse_knobs(
let header = {
if is_test {
quote! {
#[test]
#[::core::prelude::v1::test]
}
} else {
quote! {}
Expand Down Expand Up @@ -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()
Expand Down
19 changes: 19 additions & 0 deletions 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();
}

0 comments on commit a7e6771

Please sign in to comment.