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 7, 2020
1 parent 4748b25 commit 9876735
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 3 additions & 3 deletions tokio-macros/src/entry.rs
Original file line number Diff line number Diff line change
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
15 changes: 15 additions & 0 deletions tokio/tests/macros_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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 9876735

Please sign in to comment.