Skip to content

Commit

Permalink
tests/util: Improve assertion messages of `CmdResult::stderr_is_bytes…
Browse files Browse the repository at this point in the history
…`, `stdout_is_bytes`
  • Loading branch information
Joining7943 committed Jan 11, 2023
1 parent 31c9d79 commit eee6cdc
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions tests/common/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,11 @@ impl CmdResult {
/// whose bytes equal those of the passed in slice
#[track_caller]
pub fn stdout_is_bytes<T: AsRef<[u8]>>(&self, msg: T) -> &Self {
assert_eq!(self.stdout, msg.as_ref());
assert_eq!(self.stdout, msg.as_ref(),
"stdout as bytes wasn't equal to expected bytes. Result as strings:\nstdout ='{:?}'\nexpected='{:?}'",
std::str::from_utf8(&self.stdout),
std::str::from_utf8(msg.as_ref()),
);
self
}

Expand Down Expand Up @@ -555,7 +559,13 @@ impl CmdResult {
/// whose bytes equal those of the passed in slice
#[track_caller]
pub fn stderr_is_bytes<T: AsRef<[u8]>>(&self, msg: T) -> &Self {
assert_eq!(self.stderr, msg.as_ref());
assert_eq!(
&self.stderr,
msg.as_ref(),
"stderr as bytes wasn't equal to expected bytes. Result as strings:\nstderr ='{:?}'\nexpected='{:?}'",
std::str::from_utf8(&self.stderr),
std::str::from_utf8(msg.as_ref())
);
self
}

Expand Down

0 comments on commit eee6cdc

Please sign in to comment.