1use crate::task::{noop_waker_ref, panic_waker_ref};
2use futures_core::task::Context;
3
4/// Create a new [`Context`](core::task::Context) where the
5/// [waker](core::task::Context::waker) will panic if used.
6///
7/// # Examples
8///
9/// ```should_panic
10/// use futures_test::task::panic_context;
11///
12/// let cx = panic_context();
13/// cx.waker().wake_by_ref(); // Will panic
14/// ```
15pub fn panic_context() -> Context<'static> {
16 Context::from_waker(panic_waker_ref())
17}
18
19/// Create a new [`Context`](core::task::Context) where the
20/// [waker](core::task::Context::waker) will ignore any uses.
21///
22/// # Examples
23///
24/// ```
25/// use futures::future::Future;
26/// use futures::task::Poll;
27/// use futures_test::task::noop_context;
28/// use futures::pin_mut;
29///
30/// let future = async { 5 };
31/// pin_mut!(future);
32///
33/// assert_eq!(future.poll(&mut noop_context()), Poll::Ready(5));
34/// ```
35pub fn noop_context() -> Context<'static> {
36 Context::from_waker(noop_waker_ref())
37}
38