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-rs#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.
  • Loading branch information
jebrosen authored and jensim committed Jun 7, 2020
1 parent 33b7cd7 commit ae1d909
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
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
19 changes: 19 additions & 0 deletions tokio/tests/macros_test.rs
Original file line number Diff line number Diff line change
@@ -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 ae1d909

Please sign in to comment.