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