#[macro_export]
macro_rules! assert_ready_eq {
($cond:expr, $expected:expr $(,)?) => {
match $cond {
::core::task::Poll::Ready(t) => {
::core::assert_eq!(t, $expected);
t
},
::core::task::Poll::Pending => {
::core::panic!("assertion failed, expected Ready(_), got Pending");
}
}
};
($cond:expr, $expected:expr, $($arg:tt)+) => {
match $cond {
::core::task::Poll::Ready(t) => {
::core::assert_eq!(t, $expected, $($arg)+);
t
},
::core::task::Poll::Pending => {
::core::panic!("assertion failed, expected Ready(_), got Pending: {}", ::core::format_args!($($arg)+));
}
}
};
}
#[macro_export]
macro_rules! debug_assert_ready_eq {
($($arg:tt)*) => {
#[cfg(debug_assertions)]
$crate::assert_ready_eq!($($arg)*);
}
}
#[cfg(test)]
mod tests {
use core::task::Poll::{Pending, Ready};
#[test]
fn equal() {
assert_ready_eq!(Ready(42), 42);
}
#[test]
#[should_panic]
fn not_equal() {
assert_ready_eq!(Ready(42), 100);
}
#[test]
#[should_panic(expected = "assertion failed, expected Ready(_), got Pending")]
fn not_ready() {
assert_ready_eq!(Pending::<usize>, 42);
}
#[test]
#[should_panic(expected = "foo")]
fn not_equal_custom_message() {
assert_ready_eq!(Ready(1), 2, "foo");
}
#[test]
#[should_panic(expected = "assertion failed, expected Ready(_), got Pending: foo")]
fn not_ready_custom_message() {
assert_ready_eq!(Pending::<usize>, 2, "foo");
}
#[test]
#[cfg_attr(not(debug_assertions), ignore = "only run in debug mode")]
fn debug_equal() {
debug_assert_ready_eq!(Ready(42), 42);
}
#[test]
#[cfg_attr(not(debug_assertions), ignore = "only run in debug mode")]
#[should_panic]
fn debug_not_equal() {
debug_assert_ready_eq!(Ready(42), 100);
}
#[test]
#[cfg_attr(not(debug_assertions), ignore = "only run in debug mode")]
#[should_panic(expected = "assertion failed, expected Ready(_), got Pending")]
fn debug_not_ready() {
debug_assert_ready_eq!(Pending::<usize>, 42);
}
#[test]
#[cfg_attr(not(debug_assertions), ignore = "only run in debug mode")]
#[should_panic(expected = "foo")]
fn debug_not_equal_custom_message() {
debug_assert_ready_eq!(Ready(1), 2, "foo");
}
#[test]
#[cfg_attr(not(debug_assertions), ignore = "only run in debug mode")]
#[should_panic(expected = "assertion failed, expected Ready(_), got Pending: foo")]
fn debug_not_ready_custom_message() {
debug_assert_ready_eq!(Pending::<usize>, 2, "foo");
}
#[test]
#[cfg_attr(debug_assertions, ignore = "only run in release mode")]
fn debug_release_not_equal() {
debug_assert_ready_eq!(Ready(42), 100);
}
#[test]
#[cfg_attr(debug_assertions, ignore = "only run in release mode")]
fn debug_release_not_ready() {
debug_assert_ready_eq!(Pending::<usize>, 42);
}
}