• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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"))]
19 compile_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")]
26 pub 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")]
42 mod assert;
43 
44 #[cfg(feature = "std")]
45 pub mod task;
46 
47 #[cfg(feature = "std")]
48 pub mod future;
49 
50 #[cfg(feature = "std")]
51 pub mod stream;
52 
53 #[cfg(feature = "std")]
54 pub mod sink;
55 
56 #[cfg(feature = "std")]
57 pub mod io;
58 
59 mod assert_unmoved;
60 mod interleave_pending;
61 mod track_closed;
62 
63 /// Enables an `async` test function. The generated future will be run to completion with
64 /// [`futures_executor::block_on`](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")]
86 pub use futures_macro::test_internal as test;
87