Debian Codegraph @

third_party/rust/tokio/tests/macros_test.rs

raw
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]
7 async fn test_macro_can_be_used_via_use() {
8 tokio::spawn(async {}).await.unwrap();
9 }
10
11 #[tokio::test]
12 async 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]
19 pub 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]
22 async 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]
26 fn 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]
45 pub async fn issue_4175_main_1() -> ! {
46 panic!();
47 }
48 #[tokio::main]
49 pub async fn issue_4175_main_2() -> std::io::Result<()> {
50 panic!();
51 }
52 #[allow(unreachable_code)]
53 #[tokio::test]
54 pub 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]
65 pub async fn local() {
66 let _x = ();
67 }
68 #[tokio::main]
69 pub async fn item() {
70 fn _f() {}
71 }
72 #[tokio::main]
73 pub async fn semi() {
74 panic!();
75 }
76 #[tokio::main]
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]
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")]
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 }