use super::{Assertion, Debug, Display};
pub struct ShouldFail<A: Assertion>(pub A);
impl<A: Assertion> Display for ShouldFail<A> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let inner = &self.0;
write!(f, "assertion expected to fail succeeded:\n{inner}")
}
}
#[cfg(feature = "std")]
impl<A: Assertion> std::process::Termination for ShouldFail<A> {
fn report(self) -> std::process::ExitCode {
if self.0.test() {
println!("{self}");
std::process::ExitCode::FAILURE
} else {
std::process::ExitCode::SUCCESS
}
}
}
impl<A: Assertion> Assertion for ShouldFail<A> {
fn test(&self) -> bool {
!self.0.test()
}
}
impl<A: Assertion> Debug for ShouldFail<A> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
Display::fmt(self, f)
}
}