macros: add build tests for #[tokio::main] and #[tokio::test] (#1591)

This commit is contained in:
Taiki Endo
2019-09-23 04:09:30 +09:00
committed by GitHub
parent ddbb0c3836
commit 3a55aba251
6 changed files with 84 additions and 2 deletions
+1
View File
@@ -7,6 +7,7 @@ publish = false
[features]
executor-without-current-thread = ["tokio-executor"]
macros-invalid-input = ["tokio/rt-full"]
net-no-features = ["tokio-net"]
net-with-tcp = ["tokio-net/tcp"]
net-with-udp = ["tokio-net/udp"]
@@ -0,0 +1,28 @@
use build_tests::tokio;
#[tokio::main]
fn main_is_not_async() {}
#[tokio::main]
async fn main_fn_has_args(_x: u8) {}
#[tokio::main(foo)]
async fn main_attr_has_unknown_args() {}
#[tokio::main(multi_thread::bar)]
async fn main_attr_has_path_args() {}
#[tokio::test]
fn test_is_not_async() {}
#[tokio::test]
async fn test_fn_has_args(_x: u8) {}
#[tokio::test(foo)]
async fn test_attr_has_args() {}
#[tokio::test]
#[test]
async fn test_has_second_test_attr() {}
fn main() {}
@@ -0,0 +1,47 @@
error: the async keyword is missing from the function declaration
--> $DIR/macros_invalid_input.rs:4:1
|
4 | fn main_is_not_async() {}
| ^^
error: the main function cannot accept arguments
--> $DIR/macros_invalid_input.rs:7:27
|
7 | async fn main_fn_has_args(_x: u8) {}
| ^^^^^^
error: Unknown attribute foo is specified
--> $DIR/macros_invalid_input.rs:9:15
|
9 | #[tokio::main(foo)]
| ^^^
error: Must have specified ident
--> $DIR/macros_invalid_input.rs:12:15
|
12 | #[tokio::main(multi_thread::bar)]
| ^^^^^^^^^^^^^^^^^
error: the async keyword is missing from the function declaration
--> $DIR/macros_invalid_input.rs:16:1
|
16 | fn test_is_not_async() {}
| ^^
error: the test function cannot accept arguments
--> $DIR/macros_invalid_input.rs:19:27
|
19 | async fn test_fn_has_args(_x: u8) {}
| ^^^^^^
error: unexpected token
--> $DIR/macros_invalid_input.rs:21:15
|
21 | #[tokio::test(foo)]
| ^^^
error: second test attribute is supplied
--> $DIR/macros_invalid_input.rs:25:1
|
25 | #[test]
| ^^^^^^^
+4
View File
@@ -37,6 +37,7 @@ fn tokio_with_net() {
// net is present
use build_tests::tokio::net;
}
#[test]
fn compile_fail() {
let t = trybuild::TestCases::new();
@@ -44,6 +45,9 @@ fn compile_fail() {
#[cfg(feature = "executor-without-current-thread")]
t.compile_fail("tests/fail/executor_without_current_thread.rs");
#[cfg(feature = "macros-invalid-input")]
t.compile_fail("tests/fail/macros_invalid_input.rs");
#[cfg(feature = "net-no-features")]
{
t.compile_fail("tests/fail/net_without_tcp_missing_tcp.rs");