Skip to content

Commit

Permalink
Merge pull request #144 from jbtrystram/assert_error
Browse files Browse the repository at this point in the history
feat: allow getting the Assert from an AssertError
  • Loading branch information
epage authored Oct 20, 2022
2 parents 8d4bfd2 + aadf8bb commit 7b0b08b
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/assert.rs
Original file line number Diff line number Diff line change
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.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 7b0b08b

Please sign in to comment.