mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-08 00:00:13 +02:00
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.
This commit is contained in:
@@ -142,7 +142,7 @@ fn parse_knobs(
|
|||||||
let header = {
|
let header = {
|
||||||
if is_test {
|
if is_test {
|
||||||
quote! {
|
quote! {
|
||||||
#[test]
|
#[::core::prelude::v1::test]
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
quote! {}
|
quote! {}
|
||||||
@@ -334,14 +334,14 @@ pub(crate) mod old {
|
|||||||
|
|
||||||
let result = match runtime {
|
let result = match runtime {
|
||||||
Runtime::Threaded => quote! {
|
Runtime::Threaded => quote! {
|
||||||
#[test]
|
#[::core::prelude::v1::test]
|
||||||
#(#attrs)*
|
#(#attrs)*
|
||||||
#vis fn #name() #ret {
|
#vis fn #name() #ret {
|
||||||
tokio::runtime::Runtime::new().unwrap().block_on(async { #body })
|
tokio::runtime::Runtime::new().unwrap().block_on(async { #body })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Runtime::Basic | Runtime::Auto => quote! {
|
Runtime::Basic | Runtime::Auto => quote! {
|
||||||
#[test]
|
#[::core::prelude::v1::test]
|
||||||
#(#attrs)*
|
#(#attrs)*
|
||||||
#vis fn #name() #ret {
|
#vis fn #name() #ret {
|
||||||
tokio::runtime::Builder::new()
|
tokio::runtime::Builder::new()
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user