Skip to content

Commit

Permalink
feat: allow getting the Assert from an AssertError
Browse files Browse the repository at this point in the history
  • Loading branch information
jbtrystram committed Oct 18, 2022
1 parent 1e73f00 commit 36b6080
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/assert.rs
Expand Up @@ -1035,6 +1035,33 @@ impl AssertError {
fn panic<T>(self) -> T {
panic!("{}", self)
}

/// Returns the [`Assert`] wrapped into the [`Result`] produced by
/// the `try_` variants of the [`Assert`] methods.
///
/// # Examples
///
/// ```rust,no_run
/// use assert_cmd::prelude::*;
///
/// use std::process::Command;
/// use predicates::prelude::*;
///
/// let result = Command::new("echo")
/// .assert();
///
/// match result.try_success() {
/// Ok(assert) => {
/// assert.stdout(predicate::eq(b"Success\n" as &[u8]));
/// }
/// Err(err) => {
/// err.get_assert().stdout(predicate::eq(b"Err but some specific output you might want to check\n" as &[u8]));
/// }
/// }
/// ```
pub fn assert(self) -> Assert {
self.assert
}
}

impl Error for AssertError {}
Expand Down

0 comments on commit 36b6080

Please sign in to comment.