From 9de7083be89bde2e26ee5bc4f3333f5c8d13762d Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Thu, 15 Aug 2019 09:52:25 -0700 Subject: [PATCH] executor: move current-thread into crate (#1447) The `CurrentThread` executor is exposed using a feature flag. Refs: #1264 --- Cargo.toml | 2 +- azure-pipelines.yml | 14 +++++- ci/patch.toml | 1 - tokio-current-thread/CHANGELOG.md | 36 -------------- tokio-current-thread/Cargo.toml | 28 ----------- tokio-current-thread/LICENSE | 25 ---------- tokio-current-thread/README.md | 13 ----- tokio-executor/Cargo.toml | 4 ++ .../src/current_thread/mod.rs | 40 ++++++--------- .../src/current_thread}/scheduler.rs | 5 +- tokio-executor/src/lib.rs | 3 ++ .../tests/current_thread.rs | 49 +++++++------------ tokio-timer/Cargo.toml | 1 - tokio-timer/tests/hammer.rs | 2 +- tokio/Cargo.toml | 4 +- tokio/src/runtime/current_thread/builder.rs | 4 +- tokio/src/runtime/current_thread/mod.rs | 4 +- tokio/src/runtime/current_thread/runtime.rs | 7 +-- tokio/src/runtime/threadpool/background.rs | 2 +- ui-tests/Cargo.toml | 17 +++++++ ui-tests/README.md | 2 + ui-tests/src/lib.rs | 2 + ui-tests/tests/features.rs | 9 ++++ .../ui/executor_without_current_thread.rs | 3 ++ .../ui/executor_without_current_thread.stderr | 7 +++ 25 files changed, 110 insertions(+), 174 deletions(-) delete mode 100644 tokio-current-thread/CHANGELOG.md delete mode 100644 tokio-current-thread/Cargo.toml delete mode 100644 tokio-current-thread/LICENSE delete mode 100644 tokio-current-thread/README.md rename tokio-current-thread/src/lib.rs => tokio-executor/src/current_thread/mod.rs (95%) rename {tokio-current-thread/src => tokio-executor/src/current_thread}/scheduler.rs (99%) rename {tokio-current-thread => tokio-executor}/tests/current_thread.rs (93%) create mode 100644 ui-tests/Cargo.toml create mode 100644 ui-tests/README.md create mode 100644 ui-tests/src/lib.rs create mode 100644 ui-tests/tests/features.rs create mode 100644 ui-tests/tests/ui/executor_without_current_thread.rs create mode 100644 ui-tests/tests/ui/executor_without_current_thread.stderr diff --git a/Cargo.toml b/Cargo.toml index d5b7026d8..62f715b19 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,6 @@ members = [ "tokio", "tokio-buf", "tokio-codec", - "tokio-current-thread", "tokio-executor", "tokio-fs", "tokio-io", @@ -20,4 +19,5 @@ members = [ "tokio-tls", "tokio-udp", "tokio-uds", + "ui-tests", ] diff --git a/azure-pipelines.yml b/azure-pipelines.yml index ecdd26d71..c4992ae99 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -66,8 +66,8 @@ jobs: crates: tokio-buf: [] tokio-codec: [] - tokio-current-thread: [] - tokio-executor: [] + tokio-executor: + - current-thread tokio-io: - util tokio-sync: @@ -78,6 +78,16 @@ jobs: - async-traits tokio-test: [] +# Test compilation failure +- template: ci/azure-test-stable.yml + parameters: + name: test_features + displayName: Test feature flags + rust: $(nightly) + crates: + ui-tests: + - executor-without-current-thread + # - template: ci/azure-cargo-check.yml # parameters: # name: features diff --git a/ci/patch.toml b/ci/patch.toml index 5942addaa..fe95094d0 100644 --- a/ci/patch.toml +++ b/ci/patch.toml @@ -4,7 +4,6 @@ tokio = { path = "tokio" } tokio-buf = { path = "tokio-buf" } tokio-codec = { path = "tokio-codec" } -tokio-current-thread = { path = "tokio-current-thread" } tokio-executor = { path = "tokio-executor" } tokio-fs = { path = "tokio-fs" } tokio-io = { path = "tokio-io" } diff --git a/tokio-current-thread/CHANGELOG.md b/tokio-current-thread/CHANGELOG.md deleted file mode 100644 index 6d4f7d693..000000000 --- a/tokio-current-thread/CHANGELOG.md +++ /dev/null @@ -1,36 +0,0 @@ -# 0.2.0-alpha.1 (August 8, 2019) - -### Changed -- Switch to `async`, `await`, and `std::future`. - -# 0.1.6 (March 22, 2019) - -### Added -- implement `TypedExecutor` (#993). - -# 0.1.5 (March 1, 2019) - -### Fixed -- Documentation typos (#882). - -# 0.1.4 (November 21, 2018) - -* Fix shutdown on idle (#763). - -# 0.1.3 (September 27, 2018) - -* Fix minimal versions - -# 0.1.2 (September 26, 2018) - -* Implement `futures::Executor` for executor types (#563) -* Spawning performance improvements (#565) - -# 0.1.1 (August 6, 2018) - -* Implement `std::Error` for misc error types (#501) -* bugfix: Track tasks pending in spawn queue (#478) - -# 0.1.0 (June 13, 2018) - -* Extract `tokio::executor::current_thread` to a tokio-current-thread crate (#356) diff --git a/tokio-current-thread/Cargo.toml b/tokio-current-thread/Cargo.toml deleted file mode 100644 index 598b88984..000000000 --- a/tokio-current-thread/Cargo.toml +++ /dev/null @@ -1,28 +0,0 @@ -[package] -name = "tokio-current-thread" -# When releasing to crates.io: -# - Remove path dependencies -# - Update html_root_url. -# - Update doc url -# - Cargo.toml -# - Update CHANGELOG.md. -# - Create "v0.2.x" git tag. -version = "0.2.0-alpha.1" -edition = "2018" -authors = ["Tokio Contributors "] -license = "MIT" -repository = "https://github.com/tokio-rs/tokio" -homepage = "https://tokio.rs" -documentation = "https://docs.rs/tokio-current-thread/0.2.0-alpha.1/tokio_current_thread" -description = """ -Single threaded executor which manage many tasks concurrently on the current thread. -""" -keywords = ["futures", "tokio"] -categories = ["concurrency", "asynchronous"] - -[dependencies] -tokio-executor = { version = "=0.2.0-alpha.1", path = "../tokio-executor" } -crossbeam-channel = "0.3.8" - -[dev-dependencies] -tokio-sync = { version = "=0.2.0-alpha.1", path = "../tokio-sync" } diff --git a/tokio-current-thread/LICENSE b/tokio-current-thread/LICENSE deleted file mode 100644 index cdb28b4b5..000000000 --- a/tokio-current-thread/LICENSE +++ /dev/null @@ -1,25 +0,0 @@ -Copyright (c) 2019 Tokio Contributors - -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/tokio-current-thread/README.md b/tokio-current-thread/README.md deleted file mode 100644 index 2d86bacbd..000000000 --- a/tokio-current-thread/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# tokio-current-thread - -Single threaded executor for Tokio. - -## License - -This project is licensed under the [MIT license](LICENSE). - -### Contribution - -Unless you explicitly state otherwise, any contribution intentionally submitted -for inclusion in Tokio by you, shall be licensed as MIT, without any additional -terms or conditions. diff --git a/tokio-executor/Cargo.toml b/tokio-executor/Cargo.toml index 5c9ad4077..f5bc8ab28 100644 --- a/tokio-executor/Cargo.toml +++ b/tokio-executor/Cargo.toml @@ -20,7 +20,11 @@ Future execution primitives keywords = ["futures", "tokio"] categories = ["concurrency", "asynchronous"] +[features] +current-thread = ["crossbeam-channel"] + [dependencies] +crossbeam-channel = { version = "0.3.8", optional = true } [dev-dependencies] tokio = { version = "=0.2.0-alpha.1", path = "../tokio" } diff --git a/tokio-current-thread/src/lib.rs b/tokio-executor/src/current_thread/mod.rs similarity index 95% rename from tokio-current-thread/src/lib.rs rename to tokio-executor/src/current_thread/mod.rs index 771ff4f44..5daa634f7 100644 --- a/tokio-current-thread/src/lib.rs +++ b/tokio-executor/src/current_thread/mod.rs @@ -1,12 +1,3 @@ -#![doc(html_root_url = "https://docs.rs/tokio-current-thread/0.2.0-alpha.1")] -#![warn( - missing_debug_implementations, - missing_docs, - rust_2018_idioms, - unreachable_pub -)] -#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))] - //! A single-threaded executor which executes tasks on the same thread from which //! they are spawned. //! @@ -26,7 +17,10 @@ mod scheduler; -use crate::scheduler::Scheduler; +use self::scheduler::Scheduler; +use crate::park::{Park, ParkThread, Unpark}; +use crate::{EnterError, Executor, SpawnError, TypedExecutor}; + use std::cell::Cell; use std::error::Error; use std::fmt; @@ -37,8 +31,6 @@ use std::sync::{atomic, Arc}; use std::task::{Context, Poll, Waker}; use std::thread; use std::time::{Duration, Instant}; -use tokio_executor::park::{Park, ParkThread, Unpark}; -use tokio_executor::SpawnError; /// Executes tasks on the current thread pub struct CurrentThread { @@ -318,21 +310,21 @@ impl CurrentThread

{ where F: Future, { - let _enter = tokio_executor::enter().expect("failed to start `current_thread::Runtime`"); + let _enter = crate::enter().expect("failed to start `current_thread::Runtime`"); self.enter().block_on(future) } /// Run the executor to completion, blocking the thread until **all** /// spawned futures have completed. pub fn run(&mut self) -> Result<(), RunError> { - let _enter = tokio_executor::enter().expect("failed to start `current_thread::Runtime`"); + let _enter = crate::enter().expect("failed to start `current_thread::Runtime`"); self.enter().run() } /// Run the executor to completion, blocking the thread until all /// spawned futures have completed **or** `duration` time has elapsed. pub fn run_timeout(&mut self, duration: Duration) -> Result<(), RunTimeoutError> { - let _enter = tokio_executor::enter().expect("failed to start `current_thread::Runtime`"); + let _enter = crate::enter().expect("failed to start `current_thread::Runtime`"); self.enter().run_timeout(duration) } @@ -340,7 +332,7 @@ impl CurrentThread

{ /// /// This function blocks the current thread even if the executor is idle. pub fn turn(&mut self, duration: Option) -> Result { - let _enter = tokio_executor::enter().expect("failed to start `current_thread::Runtime`"); + let _enter = crate::enter().expect("failed to start `current_thread::Runtime`"); self.enter().turn(duration) } @@ -394,7 +386,7 @@ impl Drop for CurrentThread

{ } } -impl tokio_executor::Executor for CurrentThread { +impl Executor for CurrentThread { fn spawn( &mut self, future: Pin + Send>>, @@ -404,7 +396,7 @@ impl tokio_executor::Executor for CurrentThread { } } -impl tokio_executor::TypedExecutor for CurrentThread +impl TypedExecutor for CurrentThread where T: Future + 'static, { @@ -723,7 +715,7 @@ impl TaskExecutor { } } -impl tokio_executor::Executor for TaskExecutor { +impl Executor for TaskExecutor { fn spawn( &mut self, future: Pin + Send>>, @@ -732,7 +724,7 @@ impl tokio_executor::Executor for TaskExecutor { } } -impl tokio_executor::TypedExecutor for TaskExecutor +impl TypedExecutor for TaskExecutor where F: Future + 'static, { @@ -811,8 +803,8 @@ impl RunTimeoutError { } } -impl From for RunTimeoutError { - fn from(_: tokio_executor::EnterError) -> Self { +impl From for RunTimeoutError { + fn from(_: EnterError) -> Self { RunTimeoutError::new(false) } } @@ -826,8 +818,8 @@ impl BlockError { } } -impl From for BlockError { - fn from(_: tokio_executor::EnterError) -> Self { +impl From for BlockError { + fn from(_: EnterError) -> Self { BlockError { inner: None } } } diff --git a/tokio-current-thread/src/scheduler.rs b/tokio-executor/src/current_thread/scheduler.rs similarity index 99% rename from tokio-current-thread/src/scheduler.rs rename to tokio-executor/src/current_thread/scheduler.rs index d53984eb6..c688b7d37 100644 --- a/tokio-current-thread/src/scheduler.rs +++ b/tokio-executor/src/current_thread/scheduler.rs @@ -1,4 +1,6 @@ -use crate::Borrow; +use super::Borrow; +use crate::park::Unpark; + use std::cell::UnsafeCell; use std::fmt::{self, Debug}; use std::future::Future; @@ -11,7 +13,6 @@ use std::sync::{Arc, Weak}; use std::task::{Context, Poll, RawWaker, RawWakerVTable, Waker}; use std::thread; use std::usize; -use tokio_executor::park::Unpark; /// A generic task-aware scheduler. /// diff --git a/tokio-executor/src/lib.rs b/tokio-executor/src/lib.rs index df5519c91..ba56f5671 100644 --- a/tokio-executor/src/lib.rs +++ b/tokio-executor/src/lib.rs @@ -64,6 +64,9 @@ mod global; pub mod park; mod typed; +#[cfg(feature = "current-thread")] +pub mod current_thread; + pub use crate::enter::{enter, exit, Enter, EnterError}; pub use crate::error::SpawnError; pub use crate::executor::Executor; diff --git a/tokio-current-thread/tests/current_thread.rs b/tokio-executor/tests/current_thread.rs similarity index 93% rename from tokio-current-thread/tests/current_thread.rs rename to tokio-executor/tests/current_thread.rs index 48fe7bdd9..2f504aab7 100644 --- a/tokio-current-thread/tests/current_thread.rs +++ b/tokio-executor/tests/current_thread.rs @@ -1,6 +1,10 @@ #![warn(rust_2018_idioms)] #![feature(async_await)] +use tokio::sync::oneshot; +use tokio_executor::current_thread::{self, block_on_all, CurrentThread, TaskExecutor}; +use tokio_executor::TypedExecutor; + use std::any::Any; use std::cell::{Cell, RefCell}; use std::future::Future; @@ -9,9 +13,6 @@ use std::rc::Rc; use std::task::{Context, Poll}; use std::thread; use std::time::Duration; -use tokio_current_thread::{block_on_all, CurrentThread}; -use tokio_executor::TypedExecutor; -use tokio_sync::oneshot; mod from_block_on_all { use super::*; @@ -19,7 +20,7 @@ mod from_block_on_all { let cnt = Rc::new(Cell::new(0)); let c = cnt.clone(); - let msg = tokio_current_thread::block_on_all(async move { + let msg = block_on_all(async move { c.set(1 + c.get()); // Spawn! @@ -36,15 +37,13 @@ mod from_block_on_all { #[test] fn spawn() { - test(tokio_current_thread::spawn) + test(current_thread::spawn) } #[test] fn execute() { test(|f| { - tokio_current_thread::TaskExecutor::current() - .spawn(f) - .unwrap(); + TaskExecutor::current().spawn(f).unwrap(); }); } } @@ -129,15 +128,13 @@ mod from_block_on_future { #[test] fn spawn() { - test(tokio_current_thread::spawn); + test(current_thread::spawn); } #[test] fn execute() { test(|f| { - tokio_current_thread::TaskExecutor::current() - .spawn(f) - .unwrap(); + current_thread::TaskExecutor::current().spawn(f).unwrap(); }); } } @@ -185,7 +182,7 @@ mod outstanding_tasks_are_dropped_when_executor_is_dropped { #[test] fn spawn() { - test(tokio_current_thread::spawn, |rt, f| { + test(current_thread::spawn, |rt, f| { rt.spawn(f); }) } @@ -194,9 +191,7 @@ mod outstanding_tasks_are_dropped_when_executor_is_dropped { fn execute() { test( |f| { - tokio_current_thread::TaskExecutor::current() - .spawn(f) - .unwrap(); + current_thread::TaskExecutor::current().spawn(f).unwrap(); }, // Note: `CurrentThread` doesn't currently implement // `futures::Executor`, so we'll call `.spawn(...)` rather than @@ -224,7 +219,7 @@ mod run_in_future { #[should_panic] fn spawn() { block_on_all(async { - tokio_current_thread::spawn(async { + current_thread::spawn(async { block_on_all(async {}); }); }); @@ -234,7 +229,7 @@ mod run_in_future { #[should_panic] fn execute() { block_on_all(async { - tokio_current_thread::TaskExecutor::current() + current_thread::TaskExecutor::current() .spawn(async { block_on_all(async {}); }) @@ -303,15 +298,13 @@ mod tasks_are_scheduled_fairly { #[test] fn spawn() { - test(tokio_current_thread::spawn) + test(current_thread::spawn) } #[test] fn execute() { test(|f| { - tokio_current_thread::TaskExecutor::current() - .spawn(f) - .unwrap(); + current_thread::TaskExecutor::current().spawn(f).unwrap(); }) } } @@ -358,7 +351,7 @@ mod and_turn { #[test] fn spawn() { - test(tokio_current_thread::spawn, |rt, f| { + test(current_thread::spawn, |rt, f| { rt.spawn(f); }) } @@ -367,9 +360,7 @@ mod and_turn { fn execute() { test( |f| { - tokio_current_thread::TaskExecutor::current() - .spawn(f) - .unwrap(); + current_thread::TaskExecutor::current().spawn(f).unwrap(); }, // Note: `CurrentThread` doesn't currently implement // `futures::Executor`, so we'll call `.spawn(...)` rather than @@ -418,7 +409,7 @@ mod in_drop { #[test] fn spawn() { - test(tokio_current_thread::spawn, |rt, f| { + test(current_thread::spawn, |rt, f| { rt.spawn(f); }) } @@ -427,9 +418,7 @@ mod in_drop { fn execute() { test( |f| { - tokio_current_thread::TaskExecutor::current() - .spawn(f) - .unwrap(); + current_thread::TaskExecutor::current().spawn(f).unwrap(); }, // Note: `CurrentThread` doesn't currently implement // `futures::Executor`, so we'll call `.spawn(...)` rather than diff --git a/tokio-timer/Cargo.toml b/tokio-timer/Cargo.toml index 55f7e3658..e08ce7b43 100644 --- a/tokio-timer/Cargo.toml +++ b/tokio-timer/Cargo.toml @@ -37,7 +37,6 @@ slab = "0.4.1" [dev-dependencies] tokio = { version = "=0.2.0-alpha.1", path = "../tokio" } -tokio-current-thread = { version = "=0.2.0-alpha.1", path = "../tokio-current-thread" } tokio-sync = { version = "=0.2.0-alpha.1", path = "../tokio-sync", features = ["async-traits"] } tokio-test = { version = "=0.2.0-alpha.1", path = "../tokio-test" } diff --git a/tokio-timer/tests/hammer.rs b/tokio-timer/tests/hammer.rs index 50c7714b5..c61019c76 100644 --- a/tokio-timer/tests/hammer.rs +++ b/tokio-timer/tests/hammer.rs @@ -1,7 +1,7 @@ #![warn(rust_2018_idioms)] #![feature(async_await)] -use tokio_current_thread::CurrentThread; +use tokio_executor::current_thread::CurrentThread; use tokio_executor::park::{Park, Unpark, UnparkThread}; use tokio_timer::{Delay, Timer}; diff --git a/tokio/Cargo.toml b/tokio/Cargo.toml index e576802d9..27b7f7adf 100644 --- a/tokio/Cargo.toml +++ b/tokio/Cargo.toml @@ -45,8 +45,7 @@ rt-full = [ "reactor", "sync", "timer", - "tokio-current-thread", - "tokio-executor", + "tokio-executor/current-thread", "tokio-macros", "tokio-threadpool", "tracing-core", @@ -66,7 +65,6 @@ futures-util-preview = { version = "=0.3.0-alpha.18", features = ["sink"] } bytes = { version = "0.4", optional = true } num_cpus = { version = "1.8.0", optional = true } tokio-codec = { version = "=0.2.0-alpha.1", optional = true, path = "../tokio-codec" } -tokio-current-thread = { version = "=0.2.0-alpha.1", optional = true, path = "../tokio-current-thread" } tokio-fs = { version = "=0.2.0-alpha.1", optional = true, path = "../tokio-fs" } tokio-io = { version = "=0.2.0-alpha.1", optional = true, features = ["util"], path = "../tokio-io" } tokio-executor = { version = "=0.2.0-alpha.1", optional = true, path = "../tokio-executor" } diff --git a/tokio/src/runtime/current_thread/builder.rs b/tokio/src/runtime/current_thread/builder.rs index c3d413b7d..a07df2879 100644 --- a/tokio/src/runtime/current_thread/builder.rs +++ b/tokio/src/runtime/current_thread/builder.rs @@ -1,8 +1,10 @@ use crate::runtime::current_thread::Runtime; -use tokio_current_thread::CurrentThread; + +use tokio_executor::current_thread::CurrentThread; use tokio_reactor::Reactor; use tokio_timer::clock::Clock; use tokio_timer::timer::Timer; + use std::io; /// Builds a Single-threaded runtime with custom configuration values. diff --git a/tokio/src/runtime/current_thread/mod.rs b/tokio/src/runtime/current_thread/mod.rs index 5477934fe..b61413036 100644 --- a/tokio/src/runtime/current_thread/mod.rs +++ b/tokio/src/runtime/current_thread/mod.rs @@ -67,5 +67,5 @@ mod runtime; pub use self::builder::Builder; pub use self::runtime::{Handle, Runtime}; -pub use tokio_current_thread::spawn; -pub use tokio_current_thread::TaskExecutor; +pub use tokio_executor::current_thread::spawn; +pub use tokio_executor::current_thread::TaskExecutor; diff --git a/tokio/src/runtime/current_thread/runtime.rs b/tokio/src/runtime/current_thread/runtime.rs index bb58891f2..a411a0349 100644 --- a/tokio/src/runtime/current_thread/runtime.rs +++ b/tokio/src/runtime/current_thread/runtime.rs @@ -1,10 +1,11 @@ use crate::runtime::current_thread::Builder; -use tokio_current_thread::Handle as ExecutorHandle; -use tokio_current_thread::{self as current_thread, CurrentThread}; -use tokio_executor; + +use tokio_executor::current_thread::Handle as ExecutorHandle; +use tokio_executor::current_thread::{self, CurrentThread}; use tokio_reactor::{self, Reactor}; use tokio_timer::clock::{self, Clock}; use tokio_timer::timer::{self, Timer}; + use std::error::Error; use std::fmt; use std::future::Future; diff --git a/tokio/src/runtime/threadpool/background.rs b/tokio/src/runtime/threadpool/background.rs index 8e44bba9b..800c732e9 100644 --- a/tokio/src/runtime/threadpool/background.rs +++ b/tokio/src/runtime/threadpool/background.rs @@ -1,7 +1,7 @@ //! Temporary reactor + timer that runs on a background thread. This it to make //! `block_on` work. -use tokio_current_thread::CurrentThread; +use tokio_executor::current_thread::CurrentThread; use tokio_reactor::Reactor; use tokio_sync::oneshot; use tokio_timer::clock::Clock; diff --git a/ui-tests/Cargo.toml b/ui-tests/Cargo.toml new file mode 100644 index 000000000..9dc03def3 --- /dev/null +++ b/ui-tests/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "ui-tests" +version = "0.1.0" +authors = ["Carl Lerche "] +edition = "2018" +publish = false + +[features] +executor-without-current-thread = ["tokio-executor"] + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +tokio-executor = { path = "../tokio-executor", optional = true } + +[dev-dependencies] +trybuild = "1.0" diff --git a/ui-tests/README.md b/ui-tests/README.md new file mode 100644 index 000000000..f491e2bc3 --- /dev/null +++ b/ui-tests/README.md @@ -0,0 +1,2 @@ +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/ui-tests/src/lib.rs b/ui-tests/src/lib.rs new file mode 100644 index 000000000..4ab0164e1 --- /dev/null +++ b/ui-tests/src/lib.rs @@ -0,0 +1,2 @@ +#[cfg(feature = "tokio-executor")] +pub use tokio_executor; diff --git a/ui-tests/tests/features.rs b/ui-tests/tests/features.rs new file mode 100644 index 000000000..02363e880 --- /dev/null +++ b/ui-tests/tests/features.rs @@ -0,0 +1,9 @@ +#[test] +fn features() { + let t = trybuild::TestCases::new(); + + #[cfg(feature = "executor-without-current-thread")] + t.compile_fail("tests/ui/executor_without_current_thread.rs"); + + drop(t); +} diff --git a/ui-tests/tests/ui/executor_without_current_thread.rs b/ui-tests/tests/ui/executor_without_current_thread.rs new file mode 100644 index 000000000..632200f89 --- /dev/null +++ b/ui-tests/tests/ui/executor_without_current_thread.rs @@ -0,0 +1,3 @@ +use ui_tests::tokio_executor::current_thread; + +fn main() {} diff --git a/ui-tests/tests/ui/executor_without_current_thread.stderr b/ui-tests/tests/ui/executor_without_current_thread.stderr new file mode 100644 index 000000000..8ef8207f7 --- /dev/null +++ b/ui-tests/tests/ui/executor_without_current_thread.stderr @@ -0,0 +1,7 @@ +error[E0432]: unresolved import `ui_tests::tokio_executor::current_thread` + --> $DIR/executor_without_current_thread.rs:1:5 + | +1 | use ui_tests::tokio_executor::current_thread; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `current_thread` in `tokio_executor` + +For more information about this error, try `rustc --explain E0432`.