2020-08-07 20:27:53 -07:00
|
|
|
#![doc(html_root_url = "https://docs.rs/tokio-test/0.3.0")]
|
2019-08-10 00:07:57 +09:00
|
|
|
#![warn(
|
2019-05-14 10:27:36 -07:00
|
|
|
missing_debug_implementations,
|
2019-08-11 04:28:52 +09:00
|
|
|
missing_docs,
|
|
|
|
|
rust_2018_idioms,
|
|
|
|
|
unreachable_pub
|
2019-05-14 10:27:36 -07:00
|
|
|
)]
|
2019-09-13 06:46:19 -10:00
|
|
|
#![deny(intra_doc_link_resolution_failure)]
|
2019-09-19 15:50:12 +09:00
|
|
|
#![doc(test(
|
|
|
|
|
no_crate_inject,
|
|
|
|
|
attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables))
|
|
|
|
|
))]
|
2019-04-23 23:17:57 -04:00
|
|
|
|
|
|
|
|
//! Tokio and Futures based testing utilites
|
|
|
|
|
|
2019-07-11 14:41:37 -07:00
|
|
|
pub mod io;
|
2019-11-21 23:28:39 -08:00
|
|
|
|
2019-04-23 23:17:57 -04:00
|
|
|
mod macros;
|
|
|
|
|
pub mod task;
|
2019-05-03 20:43:40 -07:00
|
|
|
|
2019-08-13 21:10:26 -07:00
|
|
|
/// Runs the provided future, blocking the current thread until the
|
|
|
|
|
/// future completes.
|
|
|
|
|
///
|
|
|
|
|
/// For more information, see the documentation for
|
|
|
|
|
/// [`tokio::runtime::current_thread::Runtime::block_on`][runtime-block-on].
|
|
|
|
|
///
|
2019-08-17 23:34:25 -07:00
|
|
|
/// [runtime-block-on]: https://docs.rs/tokio/0.2.0-alpha.2/tokio/runtime/current_thread/struct.Runtime.html#method.block_on
|
2019-08-13 21:10:26 -07:00
|
|
|
pub fn block_on<F: std::future::Future>(future: F) -> F::Output {
|
2019-11-01 13:18:52 -07:00
|
|
|
use tokio::runtime;
|
2019-08-13 21:10:26 -07:00
|
|
|
|
2019-11-21 23:28:39 -08:00
|
|
|
let mut rt = runtime::Builder::new()
|
|
|
|
|
.basic_scheduler()
|
|
|
|
|
.enable_all()
|
|
|
|
|
.build()
|
|
|
|
|
.unwrap();
|
2019-11-01 13:18:52 -07:00
|
|
|
|
|
|
|
|
rt.block_on(future)
|
2019-05-03 20:43:40 -07:00
|
|
|
}
|