From 02f7264008e0333d7c4df183d3bcfbda8a6d930f Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Fri, 1 Nov 2019 13:09:32 +0900 Subject: chore: check each feature works properly (#1695) It is hard to maintain features list manually, so use cargo-hack's `--each-feature` flag. And cargo-hack provides a workaround for an issue that dev-dependencies leaking into normal build (`--no-dev-deps` flag), so removed own ci tool. Also, compared to running tests on all features, there is not much advantage in running tests on each feature, so only the default features and all features are tested. If the behavior changes depending on the feature, we need to test it as another job in CI. --- Cargo.toml | 1 - azure-pipelines.yml | 43 ++----------- ci/azure-test-stable.yml | 71 +++++++++++++++------- tests-build/Cargo.toml | 25 -------- tests-build/README.md | 2 - tests-build/src/lib.rs | 8 --- .../tests/fail/executor_without_current_thread.rs | 3 - .../fail/executor_without_current_thread.stderr | 7 --- tests-build/tests/fail/macros_invalid_input.rs | 25 -------- tests-build/tests/fail/macros_invalid_input.stderr | 41 ------------- .../tests/fail/net_without_tcp_missing_tcp.rs | 4 -- .../tests/fail/net_without_tcp_missing_tcp.stderr | 7 --- .../tests/fail/net_without_udp_missing_udp.rs | 4 -- .../tests/fail/net_without_udp_missing_udp.stderr | 7 --- .../tests/fail/net_without_uds_missing_uds.rs | 4 -- .../tests/fail/net_without_uds_missing_uds.stderr | 7 --- .../tests/fail/tokio_without_net_missing_net.rs | 3 - .../fail/tokio_without_net_missing_net.stderr | 7 --- tests-build/tests/features.rs | 62 ------------------- tokio/Cargo.toml | 17 ++++-- tokio/src/executor/current_thread/mod.rs | 2 +- tokio/src/executor/thread_pool/pool.rs | 7 ++- tokio/src/lib.rs | 6 +- 23 files changed, 77 insertions(+), 286 deletions(-) delete mode 100644 tests-build/Cargo.toml delete mode 100644 tests-build/README.md delete mode 100644 tests-build/src/lib.rs delete mode 100644 tests-build/tests/fail/executor_without_current_thread.rs delete mode 100644 tests-build/tests/fail/executor_without_current_thread.stderr delete mode 100644 tests-build/tests/fail/macros_invalid_input.rs delete mode 100644 tests-build/tests/fail/macros_invalid_input.stderr delete mode 100644 tests-build/tests/fail/net_without_tcp_missing_tcp.rs delete mode 100644 tests-build/tests/fail/net_without_tcp_missing_tcp.stderr delete mode 100644 tests-build/tests/fail/net_without_udp_missing_udp.rs delete mode 100644 tests-build/tests/fail/net_without_udp_missing_udp.stderr delete mode 100644 tests-build/tests/fail/net_without_uds_missing_uds.rs delete mode 100644 tests-build/tests/fail/net_without_uds_missing_uds.stderr delete mode 100644 tests-build/tests/fail/tokio_without_net_missing_net.rs delete mode 100644 tests-build/tests/fail/tokio_without_net_missing_net.stderr delete mode 100644 tests-build/tests/features.rs diff --git a/Cargo.toml b/Cargo.toml index 4a2a71ba..9c0250f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,5 @@ members = [ # Internal "examples", - "tests-build", "tests-integration", ] diff --git a/azure-pipelines.yml b/azure-pipelines.yml index ae2bd1bb..e60090f7 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -25,20 +25,8 @@ jobs: displayName: Test tokio cross: true crates: - tokio: - - fs - - io - - io-util - - net-driver - - process - - rt-full - - signal - - sync - - tcp - - timer - - udp - - uds - tests-integration: [] + - tokio + - tests-integration # Test crates that are NOT platform specific - template: ci/azure-test-stable.yml @@ -47,29 +35,10 @@ jobs: displayName: Test sub crates - rust: beta crates: - tokio-macros: [] - tokio-test: [] - tokio-util: [] - examples: [] - -# Test compilation failure -# Disable pending: https://github.com/tokio-rs/tokio/pull/1695#issuecomment-547045383 -# - template: ci/azure-test-stable.yml -# parameters: -# name: test_features -# displayName: Test feature flags -# rust: beta -# crates: -# tests-build: -# # - tokio-executor -# # - executor-without-current-thread -# # - macros-invalid-input -# # - net-no-features -# # - net-with-tcp -# # - net-with-udp -# # - net-with-uds -# # - tokio-no-features -# # - tokio-with-net + - tokio-macros + - tokio-test + - tokio-util + - examples # Run loom tests - template: ci/azure-loom.yml diff --git a/ci/azure-test-stable.yml b/ci/azure-test-stable.yml index f0ff7a7c..93e9ee13 100644 --- a/ci/azure-test-stable.yml +++ b/ci/azure-test-stable.yml @@ -20,6 +20,11 @@ jobs: # rust_version: stable rust_version: ${{ parameters.rust }} + - script: cargo install cargo-hack + displayName: Install cargo-hack + # FIXME(taiki-e): many features of current cargo-hack are not available on windows: https://github.com/taiki-e/cargo-hack/issues/3 + condition: not(eq(variables['Agent.OS'], 'Windows_NT')) + - template: azure-is-release.yml - ${{ each crate in parameters.crates }}: @@ -28,17 +33,28 @@ jobs: env: LOOM_MAX_PREEMPTIONS: 2 CI: 'True' - displayName: ${{ crate.key }} - cargo test - workingDirectory: $(Build.SourcesDirectory)/${{ crate.key }} - - # Run with each specified feature - - ${{ each feature in crate.value }}: - - script: cargo test --no-default-features --features ${{ feature }} - env: - LOOM_MAX_PREEMPTIONS: 2 - CI: 'True' - displayName: ${{ crate.key }} - cargo test --features ${{ feature }} - workingDirectory: $(Build.SourcesDirectory)/${{ crate.key }} + displayName: ${{ crate }} - cargo test + workingDirectory: $(Build.SourcesDirectory)/${{ crate }} + + # Run with all crate features + - script: cargo test --all-features + env: + LOOM_MAX_PREEMPTIONS: 2 + CI: 'True' + displayName: ${{ crate }} - cargo test --all-features + workingDirectory: $(Build.SourcesDirectory)/${{ crate }} + + # Check each specified feature works properly + # * --each-feature - run for each feature which includes --no-default-features and default features of package + # * --no-dev-deps - build without dev-dependencies to avoid https://github.com/rust-lang/cargo/issues/4866 + - script: cargo hack check --each-feature --no-dev-deps + env: + LOOM_MAX_PREEMPTIONS: 2 + CI: 'True' + displayName: ${{ crate }} - cargo hack check --each-feature + workingDirectory: $(Build.SourcesDirectory)/${{ crate }} + # FIXME(taiki-e): many features of current cargo-hack are not available on windows: https://github.com/taiki-e/cargo-hack/issues/3 + condition: not(eq(variables['Agent.OS'], 'Windows_NT')) - template: azure-patch-crates.yml @@ -48,14 +64,25 @@ jobs: env: LOOM_MAX_PREEMPTIONS: 2 CI: 'True' - displayName: ${{ crate.key }} - cargo test - workingDirectory: $(Build.SourcesDirectory)/${{ crate.key }} - - # Run with each specified feature - - ${{ each feature in crate.value }}: - - script: cargo test --no-default-features --features ${{ feature }} - env: - LOOM_MAX_PREEMPTIONS: 2 - CI: 'True' - displayName: ${{ crate.key }} - cargo test --features ${{ feature }} - workingDirectory: $(Build.SourcesDirectory)/${{ crate.key }} + displayName: ${{ crate }} - cargo test + workingDirectory: $(Build.SourcesDirectory)/${{ crate }} + + # Run with all crate features + - script: cargo test --all-features + env: + LOOM_MAX_PREEMPTIONS: 2 + CI: 'True' + displayName: ${{ crate }} - cargo test --all-features + workingDirectory: $(Build.SourcesDirectory)/${{ crate }} + + # Check each specified feature works properly + # * --each-feature - run for each feature which includes --no-default-features and default features of package + # * --no-dev-deps - build without dev-dependencies to avoid https://github.com/rust-lang/cargo/issues/4866 + - script: cargo hack check --each-feature --no-dev-deps + env: + LOOM_MAX_PREEMPTIONS: 2 + CI: 'True' + displayName: ${{ crate }} - cargo hack check --each-feature + workingDirectory: $(Build.SourcesDirectory)/${{ crate }} + # FIXME(taiki-e): many features of current cargo-hack are not available on windows: https://github.com/taiki-e/cargo-hack/issues/3 + condition: not(eq(variables['Agent.OS'], 'Windows_NT')) diff --git a/tests-build/Cargo.toml b/tests-build/Cargo.toml deleted file mode 100644 index 36dbc883..00000000 --- a/tests-build/Cargo.toml +++ /dev/null @@ -1,25 +0,0 @@ -[package] -name = "tests-build" -version = "0.1.0" -authors = ["Tokio Contributors "] -edition = "2018" -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"] -# net-with-uds = ["tokio-net/uds"] -# net-with-process = ["tokio-net/process"] -# tokio-no-features = ["tokio"] -# tokio-with-net = ["tokio/net-full"] - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -# tokio = { path = "../tokio", optional = true, default-features = false } - -[dev-dependencies] -trybuild = "1.0" diff --git a/tests-build/README.md b/tests-build/README.md deleted file mode 100644 index f491e2bc..00000000 --- a/tests-build/README.md +++ /dev/null @@ -1,2 +0,0 @@ -Tests the various combination of feature flags. This is broken out to a separate -crate to work around limitations with cargo features. diff --git a/tests-build/src/lib.rs b/tests-build/src/lib.rs deleted file mode 100644 index 7f38a440..00000000 --- a/tests-build/src/lib.rs +++ /dev/null @@ -1,8 +0,0 @@ -#[cfg(feature = "tokio-executor")] -pub use tokio_executor; - -#[cfg(feature = "tokio-net")] -pub use tokio_net; - -#[cfg(feature = "tokio")] -pub use tokio; diff --git a/tests-build/tests/fail/executor_without_current_thread.rs b/tests-build/tests/fail/executor_without_current_thread.rs deleted file mode 100644 index 205ce7e4..00000000 --- a/tests-build/tests/fail/executor_without_current_thread.rs +++ /dev/null @@ -1,3 +0,0 @@ -use tests_build::tokio_executor::current_thread; - -fn main() {} diff --git a/tests-build/tests/fail/executor_without_current_thread.stderr b/tests-build/tests/fail/executor_without_current_thread.stderr deleted file mode 100644 index f2287c3f..00000000 --- a/tests-build/tests/fail/executor_without_current_thread.stderr +++ /dev/null @@ -1,7 +0,0 @@ -error[E0432]: unresolved import `tests_build::tokio_executor::current_thread` - --> $DIR/executor_without_current_thread.rs:1:5 - | -1 | use tests_build::tokio_executor::current_thread; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `current_thread` in `tokio_executor` - -For more information about this error, try `rustc --explain E0432`. diff --git a/tests-build/tests/fail/macros_invalid_input.rs b/tests-build/tests/fail/macros_invalid_input.rs deleted file mode 100644 index 5b1a8adc..00000000 --- a/tests-build/tests/fail/macros_invalid_input.rs +++ /dev/null @@ -1,25 +0,0 @@ -use tests_build::tokio; - -#[tokio::main] -fn main_is_not_async() {} - -#[tokio::main(foo)] -async fn main_attr_has_unknown_args() {} - -#[tokio::main(threadpool::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() {} diff --git a/tests-build/tests/fail/macros_invalid_input.stderr b/tests-build/tests/fail/macros_invalid_input.stderr deleted file mode 100644 index 12373486..00000000 --- a/tests-build/tests/fail/macros_invalid_input.stderr +++ /dev/null @@ -1,41 +0,0 @@ -error: the async keyword is missing from the function declaration - --> $DIR/macros_invalid_input.rs:4:1 - | -4 | fn main_is_not_async() {} - | ^^ - -error: Unknown attribute foo is specified; expected `current_thread` or `threadpool` - --> $DIR/macros_invalid_input.rs:6:15 - | -6 | #[tokio::main(foo)] - | ^^^ - -error: Must have specified ident - --> $DIR/macros_invalid_input.rs:9:15 - | -9 | #[tokio::main(threadpool::bar)] - | ^^^^^^^^^^^^^^^ - -error: the async keyword is missing from the function declaration - --> $DIR/macros_invalid_input.rs:13:1 - | -13 | fn test_is_not_async() {} - | ^^ - -error: the test function cannot accept arguments - --> $DIR/macros_invalid_input.rs:16:27 - | -16 | async fn test_fn_has_args(_x: u8) {} - | ^^^^^^ - -error: Unknown attribute foo is specified; expected `current_thread` or `threadpool` - --> $DIR/macros_invalid_input.rs:18:15 - | -18 | #[tokio::test(foo)] - | ^^^ - -error: second test attribute is supplied - --> $DIR/macros_invalid_input.rs:22:1 - | -22 | #[test] - | ^^^^^^^ diff --git a/tests-build/tests/fail/net_without_tcp_missing_tcp.rs b/tests-build/tests/fail/net_without_tcp_missing_tcp.rs deleted file mode 100644 index 80010233..00000000 --- a/tests-build/tests/fail/net_without_tcp_missing_tcp.rs +++ /dev/null @@ -1,4 +0,0 @@ -use tests_build::tokio_net::tcp; - -fn main() {} - diff --git a/tests-build/tests/fail/net_without_tcp_missing_tcp.stderr b/tests-build/tests/fail/net_without_tcp_missing_tcp.stderr deleted file mode 100644 index 83ff59fb..00000000 --- a/tests-build/tests/fail/net_without_tcp_missing_tcp.stderr +++ /dev/null @@ -1,7 +0,0 @@ -error[E0432]: unresolved import `tests_build::tokio_net::tcp` - --> $DIR/net_without_tcp_missing_tcp.rs:1:5 - | -1 | use tests_build::tokio_net::tcp; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `tcp` in `tokio_net` - -For more information about this error, try `rustc --explain E0432`. diff --git a/tests-build/tests/fail/net_without_udp_missing_udp.rs b/tests-build/tests/fail/net_without_udp_missing_udp.rs deleted file mode 100644 index 6731af93..00000000 --- a/tests-build/tests/fail/net_without_udp_missing_udp.rs +++ /dev/null @@ -1,4 +0,0 @@ -use tests_build::tokio_net::udp; - -fn main() {} - diff --git a/tests-build/tests/fail/net_without_udp_missing_udp.stderr b/tests-build/tests/fail/net_without_udp_missing_udp.stderr deleted file mode 100644 index e3471a79..00000000 --- a/tests-build/tests/fail/net_without_udp_missing_udp.stderr +++ /dev/null @@ -1,7 +0,0 @@ -error[E0432]: unresolved import `tests_build::tokio_net::udp` - --> $DIR/net_without_udp_missing_udp.rs:1:5 - | -1 | use tests_build::tokio_net::udp; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `udp` in `tokio_net` - -For more information about this error, try `rustc --explain E0432`. diff --git a/tests-build/tests/fail/net_without_uds_missing_uds.rs b/tests-build/tests/fail/net_without_uds_missing_uds.rs deleted file mode 100644 index d48a5eb4..00000000 --- a/tests-build/tests/fail/net_without_uds_missing_uds.rs +++ /dev/null @@ -1,4 +0,0 @@ -use tests_build::tokio_net::uds; - -fn main() {} - diff --git a/tests-build/tests/fail/net_without_uds_missing_uds.stderr b/tests-build/tests/fail/net_without_uds_missing_uds.stderr deleted file mode 100644 index ad79fe18..00000000 --- a/tests-build/tests/fail/net_without_uds_missing_uds.stderr +++ /dev/null @@ -1,7 +0,0 @@ -error[E0432]: unresolved import `tests_build::tokio_net::uds` - --> $DIR/net_without_uds_missing_uds.rs:1:5 - | -1 | use tests_build::tokio_net::uds; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `uds` in `tokio_net` - -For more information about this error, try `rustc --explain E0432`. diff --git a/tests-build/tests/fail/tokio_without_net_missing_net.rs b/tests-build/tests/fail/tokio_without_net_missing_net.rs deleted file mode 100644 index f2e27836..00000000 --- a/tests-build/tests/fail/tokio_without_net_missing_net.rs +++ /dev/null @@ -1,3 +0,0 @@ -use tests_build::tokio::net; - -fn main() {} diff --git a/tests-build/tests/fail/tokio_without_net_missing_net.stderr b/tests-build/tests/fail/tokio_without_net_missing_net.stderr deleted file mode 100644 index 4435b0a6..00000000 --- a/tests-build/tests/fail/tokio_without_net_missing_net.stderr +++ /dev/null @@ -1,7 +0,0 @@ -error[E0432]: unresolved import `tests_build::tokio::net` - --> $DIR/tokio_without_net_missing_net.rs:1:5 - | -1 | use tests_build::tokio::net; - | ^^^^^^^^^^^^^^^^^^^^^^^ no `net` in `tokio` - -For more information about this error, try `rustc --explain E0432`. diff --git a/tests-build/tests/features.rs b/tests-build/tests/features.rs deleted file mode 100644 index b40e44ed..00000000 --- a/tests-build/tests/features.rs +++ /dev/null @@ -1,62 +0,0 @@ -#![allow(unused_imports)] - -#[test] -#[cfg(feature = "tokio-net")] -fn net_default() { - use tests_build::tokio_net::driver::{set_default, Handle, Reactor, Registration}; - use tests_build::tokio_net::util::PollEvented; -} - -#[test] -#[cfg(feature = "net-with-tcp")] -fn net_with_tcp() { - use tests_build::tokio_net::tcp; -} - -#[test] -#[cfg(feature = "net-with-udp")] -fn net_with_udp() { - use tests_build::tokio_net::udp; -} - -#[test] -#[cfg(feature = "net-with-uds")] -fn net_with_uds() { - use tests_build::tokio_net::uds; -} - -#[test] -#[cfg(feature = "net-with-process")] -fn net_with_process() { - use tests_build::tokio_net::process; -} - -#[test] -#[cfg(feature = "tokio-with-net")] -fn tokio_with_net() { - // net is present - use tests_build::tokio::net; -} - -#[test] -fn compile_fail() { - let t = trybuild::TestCases::new(); - - #[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"); - t.compile_fail("tests/fail/net_without_udp_missing_udp.rs"); - t.compile_fail("tests/fail/net_without_uds_missing_uds.rs"); - } - - #[cfg(feature = "tokio-no-features")] - t.compile_fail("tests/fail/tokio_without_net_missing_net.rs"); - - drop(t); -} diff --git a/tokio/Cargo.toml b/tokio/Cargo.toml index 057055e2..48b27a39 100644 --- a/tokio/Cargo.toml +++ b/tokio/Cargo.toml @@ -36,19 +36,24 @@ default = [ "timer", ] -blocking = [] -fs = ["blocking"] +executor-core = [] +blocking = ["executor-core", "sync"] +fs = ["blocking", "io-traits"] io-traits = ["bytes", "iovec"] io-util = ["io-traits", "pin-project", "memchr"] io = ["io-traits", "io-util"] macros = ["tokio-macros"] net-full = ["tcp", "udp", "uds"] -net-driver = ["mio", "blocking", "lazy_static"] +net-driver = ["io-traits", "mio", "blocking", "lazy_static"] rt-current-thread = [ + "executor-core", "crossbeam-channel", "timer", + "sync", + "net-driver", ] rt-full = [ + "executor-core", "macros", "num_cpus", "net-full", @@ -61,11 +66,13 @@ signal = [ "libc", "mio-uds", "net-driver", - "signal-hook-registry" + "signal-hook-registry", + "winapi/consoleapi", + "winapi/minwindef", ] sync = ["fnv"] tcp = ["io", "net-driver"] -timer = ["slab"] +timer = ["executor-core", "sync", "slab"] udp = ["io", "net-driver"] uds = ["io", "net-driver", "mio-uds", "libc"] process = [ diff --git a/tokio/src/executor/current_thread/mod.rs b/tokio/src/executor/current_thread/mod.rs index dcc9c51a..62619f2a 100644 --- a/tokio/src/executor/current_thread/mod.rs +++ b/tokio/src/executor/current_thread/mod.rs @@ -18,10 +18,10 @@ mod scheduler; use self::scheduler::{Scheduler, TickArgs}; -use crate::executor::{EnterError, Executor, SpawnError, TypedExecutor}; #[cfg(feature = "blocking")] use crate::executor::blocking::{Pool, PoolWaiter}; use crate::executor::park::{Park, ParkThread, Unpark}; +use crate::executor::{EnterError, Executor, SpawnError, TypedExecutor}; use std::cell::Cell; use std::error::Error; diff --git a/tokio/src/executor/thread_pool/pool.rs b/tokio/src/executor/thread_pool/pool.rs index 1da4239b..6a83e97d 100644 --- a/tokio/src/executor/thread_pool/pool.rs +++ b/tokio/src/executor/thread_pool/pool.rs @@ -68,8 +68,11 @@ impl ThreadPool { F: Future, { crate::executor::global::with_threadpool(self, || { - let mut enter = crate::executor::enter().expect("attempting to block while on a Tokio executor"); - crate::executor::blocking::with_pool(self.spawner.blocking_pool(), || enter.block_on(future)) + let mut enter = + crate::executor::enter().expect("attempting to block while on a Tokio executor"); + crate::executor::blocking::with_pool(self.spawner.blocking_pool(), || { + enter.block_on(future) + }) }) } diff --git a/tokio/src/lib.rs b/tokio/src/lib.rs index 94eb3072..f42a8a1e 100644 --- a/tokio/src/lib.rs +++ b/tokio/src/lib.rs @@ -95,7 +95,7 @@ pub mod fs; pub mod future; -#[cfg(feature = "io")] +#[cfg(feature = "io-traits")] pub mod io; #[cfg(feature = "net-driver")] @@ -121,8 +121,10 @@ pub mod sync; #[cfg(feature = "timer")] pub mod timer; +#[cfg(feature = "executor-core")] +pub mod executor; + if_runtime! { - pub mod executor; pub mod runtime; #[doc(inline)] -- cgit v1.2.3