1 #![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threading 2 3 use tokio::test; 4 5 #[test] test_macro_can_be_used_via_use()6async fn test_macro_can_be_used_via_use() { 7 tokio::spawn(async {}).await.unwrap(); 8 } 9 10 #[tokio::test] test_macro_is_resilient_to_shadowing()11async fn test_macro_is_resilient_to_shadowing() { 12 tokio::spawn(async {}).await.unwrap(); 13 } 14 15 // https://github.com/tokio-rs/tokio/issues/3403 16 #[rustfmt::skip] // this `rustfmt::skip` is necessary because unused_braces does not warn if the block contains newline. 17 #[tokio::main] unused_braces_main()18pub async fn unused_braces_main() { println!("hello") } 19 #[rustfmt::skip] // this `rustfmt::skip` is necessary because unused_braces does not warn if the block contains newline. 20 #[tokio::test] unused_braces_test()21async fn unused_braces_test() { assert_eq!(1 + 1, 2) } 22 23 // https://github.com/tokio-rs/tokio/pull/3766#issuecomment-835508651 24 #[std::prelude::v1::test] trait_method()25fn trait_method() { 26 trait A { 27 fn f(self); 28 } 29 impl A for () { 30 #[tokio::main] 31 async fn f(self) {} 32 } 33 ().f() 34 } 35 36 // https://github.com/tokio-rs/tokio/issues/4175 37 #[tokio::main] issue_4175_main_1() -> !38pub async fn issue_4175_main_1() -> ! { 39 panic!(); 40 } 41 #[tokio::main] issue_4175_main_2() -> std::io::Result<()>42pub async fn issue_4175_main_2() -> std::io::Result<()> { 43 panic!(); 44 } 45 #[allow(unreachable_code)] 46 #[tokio::test] issue_4175_test() -> std::io::Result<()>47pub async fn issue_4175_test() -> std::io::Result<()> { 48 return Ok(()); 49 panic!(); 50 } 51 52 // https://github.com/tokio-rs/tokio/issues/4175 53 #[allow(clippy::let_unit_value)] 54 pub mod clippy_semicolon_if_nothing_returned { 55 #![deny(clippy::semicolon_if_nothing_returned)] 56 57 #[tokio::main] local()58 pub async fn local() { 59 let _x = (); 60 } 61 #[tokio::main] item()62 pub async fn item() { 63 fn _f() {} 64 } 65 #[tokio::main] semi()66 pub async fn semi() { 67 panic!(); 68 } 69 #[tokio::main] empty()70 pub async fn empty() { 71 // To trigger clippy::semicolon_if_nothing_returned lint, the block needs to contain newline. 72 } 73 } 74 75 // https://github.com/tokio-rs/tokio/issues/5243 76 pub mod issue_5243 { 77 macro_rules! mac { 78 (async fn $name:ident() $b:block) => { 79 #[::tokio::test] 80 async fn $name() { 81 $b 82 } 83 }; 84 } 85 mac!( 86 async fn foo() {} 87 ); 88 } 89