From 38bff0adda393f8121225727d93cb342d8363979 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Tue, 21 Jan 2020 10:46:32 -0800 Subject: macros: fix `#[tokio::main]` without rt-core (#2139) The Tokio runtime provides a "shell" runtime when `rt-core` is not available. This shell runtime is enough to support `#[tokio::main`] and `#[tokio::test]. A previous change disabled these two attr macros when `rt-core` was not selected. This patch fixes this by re-enabling the `main` and `test` attr macros without `rt-core` and adds some integration tests to prevent future regressions. --- tests-integration/Cargo.toml | 11 ++++++++--- tests-integration/src/lib.rs | 6 ++---- tests-integration/tests/macros_main.rs | 25 +++++++++++++++++++++++++ tests-integration/tests/process_stdio.rs | 1 + 4 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 tests-integration/tests/macros_main.rs (limited to 'tests-integration') diff --git a/tests-integration/Cargo.toml b/tests-integration/Cargo.toml index 265d7d6d..3cca17a7 100644 --- a/tests-integration/Cargo.toml +++ b/tests-integration/Cargo.toml @@ -5,11 +5,16 @@ authors = ["Tokio Contributors "] edition = "2018" publish = false +[features] +full = ["tokio/full", "tokio-test"] +macros = ["tokio/macros"] +rt-core = ["tokio/rt-core"] +rt-threaded = ["rt-core", "tokio/rt-threaded"] + [dependencies] -tokio = { path = "../tokio", features = ["full"] } +tokio = { path = "../tokio" } +tokio-test = { path = "../tokio-test", optional = true } doc-comment = "0.3.1" [dev-dependencies] -tokio-test = { path = "../tokio-test" } - futures = { version = "0.3.0", features = ["async-await"] } diff --git a/tests-integration/src/lib.rs b/tests-integration/src/lib.rs index 74795f29..b07714f4 100644 --- a/tests-integration/src/lib.rs +++ b/tests-integration/src/lib.rs @@ -1,4 +1,2 @@ -use doc_comment::doc_comment; - -// #[doc = include_str!("../../README.md")] -doc_comment!(include_str!("../../README.md")); +#[cfg(feature = "full")] +doc_comment::doc_comment!(include_str!("../../README.md")); diff --git a/tests-integration/tests/macros_main.rs b/tests-integration/tests/macros_main.rs new file mode 100644 index 00000000..182e2779 --- /dev/null +++ b/tests-integration/tests/macros_main.rs @@ -0,0 +1,25 @@ +#![cfg(feature = "macros")] + +#[tokio::main] +async fn basic_main() -> usize { + 1 +} + +#[cfg(feature = "rt-core")] +mod spawn { + #[tokio::main] + async fn spawning() -> usize { + let join = tokio::spawn(async { 1 }); + join.await.unwrap() + } + + #[test] + fn main_with_spawn() { + assert_eq!(1, spawning()); + } +} + +#[test] +fn shell() { + assert_eq!(1, basic_main()); +} diff --git a/tests-integration/tests/process_stdio.rs b/tests-integration/tests/process_stdio.rs index de7cf025..8bf2c149 100644 --- a/tests-integration/tests/process_stdio.rs +++ b/tests-integration/tests/process_stdio.rs @@ -1,4 +1,5 @@ #![warn(rust_2018_idioms)] +#![cfg(feature = "full")] use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader}; use tokio::process::{Child, Command}; -- cgit v1.2.3