Skip to content

Commit aadf8bb

Browse files
committed
feat: Allow getting the Assert from an AssertError
1 parent 1e73f00 commit aadf8bb

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/assert.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,33 @@ impl AssertError {
10351035
fn panic<T>(self) -> T {
10361036
panic!("{}", self)
10371037
}
1038+
1039+
/// Returns the [`Assert`] wrapped into the [`Result`] produced by
1040+
/// the `try_` variants of the [`Assert`] methods.
1041+
///
1042+
/// # Examples
1043+
///
1044+
/// ```rust,no_run
1045+
/// use assert_cmd::prelude::*;
1046+
///
1047+
/// use std::process::Command;
1048+
/// use predicates::prelude::*;
1049+
///
1050+
/// let result = Command::new("echo")
1051+
/// .assert();
1052+
///
1053+
/// match result.try_success() {
1054+
/// Ok(assert) => {
1055+
/// assert.stdout(predicate::eq(b"Success\n" as &[u8]));
1056+
/// }
1057+
/// Err(err) => {
1058+
/// err.assert().stdout(predicate::eq(b"Err but some specific output you might want to check\n" as &[u8]));
1059+
/// }
1060+
/// }
1061+
/// ```
1062+
pub fn assert(self) -> Assert {
1063+
self.assert
1064+
}
10381065
}
10391066

10401067
impl Error for AssertError {}

0 commit comments

Comments
 (0)