1 #![allow(unknown_lints, unexpected_cfgs)] 2 #![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threading 3 4 use tokio::test; 5 6 #[test] test_macro_can_be_used_via_use()7async fn test_macro_can_be_used_via_use() { 8 tokio::spawn(async {}).await.unwrap(); 9 } 10 11 #[tokio::test] test_macro_is_resilient_to_shadowing()12async fn test_macro_is_resilient_to_shadowing() { 13 tokio::spawn(async {}).await.unwrap(); 14 } 15 16 // https://github.com/tokio-rs/tokio/issues/3403 17 #[rustfmt::skip] // this `rustfmt::skip` is necessary because unused_braces does not warn if the block contains newline. 18 #[tokio::main] unused_braces_main()19pub async fn unused_braces_main() { println!("hello") } 20 #[rustfmt::skip] // this `rustfmt::skip` is necessary because unused_braces does not warn if the block contains newline. 21 #[tokio::test] unused_braces_test()22async fn unused_braces_test() { assert_eq!(1 + 1, 2) } 23 24 // https://github.com/tokio-rs/tokio/pull/3766#issuecomment-835508651 25 #[std::prelude::v1::test] trait_method()26fn trait_method() { 27 trait A { 28 fn f(self); 29 30 fn g(self); 31 } 32 impl A for () { 33 #[tokio::main] 34 async fn f(self) { 35 self.g() 36 } 37 38 fn g(self) {} 39 } 40 ().f() 41 } 42 43 // https://github.com/tokio-rs/tokio/issues/4175 44 #[tokio::main] issue_4175_main_1() -> !45pub async fn issue_4175_main_1() -> ! { 46 panic!(); 47 } 48 #[tokio::main] issue_4175_main_2() -> std::io::Result<()>49pub async fn issue_4175_main_2() -> std::io::Result<()> { 50 panic!(); 51 } 52 #[allow(unreachable_code)] 53 #[tokio::test] issue_4175_test() -> std::io::Result<()>54pub async fn issue_4175_test() -> std::io::Result<()> { 55 return Ok(()); 56 panic!(); 57 } 58 59 // https://github.com/tokio-rs/tokio/issues/4175 60 #[allow(clippy::let_unit_value)] 61 pub mod clippy_semicolon_if_nothing_returned { 62 #![deny(clippy::semicolon_if_nothing_returned)] 63 64 #[tokio::main] local()65 pub async fn local() { 66 let _x = (); 67 } 68 #[tokio::main] item()69 pub async fn item() { 70 fn _f() {} 71 } 72 #[tokio::main] semi()73 pub async fn semi() { 74 panic!(); 75 } 76 #[tokio::main] empty()77 pub async fn empty() { 78 // To trigger clippy::semicolon_if_nothing_returned lint, the block needs to contain newline. 79 } 80 } 81 82 // https://github.com/tokio-rs/tokio/issues/5243 83 pub mod issue_5243 { 84 macro_rules! mac { 85 (async fn $name:ident() $b:block) => { 86 #[::tokio::test] 87 async fn $name() { 88 $b 89 } 90 }; 91 } 92 mac!( 93 async fn foo() {} 94 ); 95 } 96 97 #[cfg(tokio_unstable)] 98 pub mod macro_rt_arg_unhandled_panic { 99 use tokio_test::assert_err; 100 101 #[tokio::test(flavor = "current_thread", unhandled_panic = "shutdown_runtime")] 102 #[should_panic] unhandled_panic_shutdown_runtime()103 async fn unhandled_panic_shutdown_runtime() { 104 let _ = tokio::spawn(async { 105 panic!("This panic should shutdown the runtime."); 106 }) 107 .await; 108 } 109 110 #[tokio::test(flavor = "current_thread", unhandled_panic = "ignore")] unhandled_panic_ignore()111 async fn unhandled_panic_ignore() { 112 let rt = tokio::spawn(async { 113 panic!("This panic should be forwarded to rt as an error."); 114 }) 115 .await; 116 assert_err!(rt); 117 } 118 } 119