futures_test/
lib.rs

1//! Utilities to make testing [`Future`s](futures_core::future::Future) easier
2
3#![warn(
4    missing_debug_implementations,
5    missing_docs,
6    rust_2018_idioms,
7    single_use_lifetimes,
8    unreachable_pub
9)]
10#![doc(test(
11    no_crate_inject,
12    attr(
13        deny(warnings, rust_2018_idioms, single_use_lifetimes),
14        allow(dead_code, unused_assignments, unused_variables)
15    )
16))]
17
18#[cfg(not(feature = "std"))]
19compile_error!(
20    "`futures-test` must have the `std` feature activated, this is a default-active feature"
21);
22
23// Not public API.
24#[doc(hidden)]
25#[cfg(feature = "std")]
26pub mod __private {
27    pub use futures_core::{future, stream, task};
28    pub use futures_executor::block_on;
29    pub use std::{
30        option::Option::{None, Some},
31        pin::Pin,
32        result::Result::{Err, Ok},
33    };
34
35    pub mod assert {
36        pub use crate::assert::*;
37    }
38}
39
40#[macro_use]
41#[cfg(feature = "std")]
42mod assert;
43
44#[cfg(feature = "std")]
45pub mod task;
46
47#[cfg(feature = "std")]
48pub mod future;
49
50#[cfg(feature = "std")]
51pub mod stream;
52
53#[cfg(feature = "std")]
54pub mod sink;
55
56#[cfg(feature = "std")]
57pub mod io;
58
59mod assert_unmoved;
60mod interleave_pending;
61mod track_closed;
62
63/// Enables an `async` test function. The generated future will be run to completion with
64/// [`futures_executor::block_on`].
65///
66/// ```
67/// #[futures_test::test]
68/// async fn my_test() {
69///     let fut = async { true };
70///     assert!(fut.await);
71/// }
72/// ```
73///
74/// This is equivalent to the following code:
75///
76/// ```
77/// #[test]
78/// fn my_test() {
79///     futures::executor::block_on(async move {
80///         let fut = async { true };
81///         assert!(fut.await);
82///     })
83/// }
84/// ```
85#[cfg(feature = "std")]
86pub use futures_macro::test_internal as test;