Skip to content

Commit

Permalink
make assert_stderr_contains print its contents on panic
Browse files Browse the repository at this point in the history
  • Loading branch information
Oneirical committed Jun 11, 2024
1 parent 1b55ff2 commit 0c0edce
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/tools/run-make-support/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,16 @@ impl CompletedProcess {
/// Checks that trimmed `stdout` matches trimmed `content`.
#[track_caller]
pub fn assert_stdout_equals<S: AsRef<str>>(&self, content: S) -> &Self {
assert_eq!(self.stdout_utf8().trim(), content.as_ref().trim());
assert_eq!(
self.stdout_utf8().trim(),
content.as_ref().trim(),
"{}",
format!(
"The stdout \"{}\" did not equal the string \"{}\"",
self.stdout_utf8().as_str(),
content.as_ref().trim()
)
);
self
}

Expand All @@ -176,18 +185,28 @@ impl CompletedProcess {
/// Checks that trimmed `stderr` matches trimmed `content`.
#[track_caller]
pub fn assert_stderr_equals<S: AsRef<str>>(&self, content: S) -> &Self {
assert_eq!(self.stderr_utf8().trim(), content.as_ref().trim());
assert_eq!(
self.stderr_utf8().trim(),
content.as_ref().trim(),
"{}",
format!(
"The stderr \"{}\" did not equal the string \"{}\"",
self.stderr_utf8().as_str(),
content.as_ref().trim()
)
);
self
}

#[track_caller]
pub fn assert_stderr_contains<S: AsRef<str>>(&self, needle: S) -> &Self {
assert!(
self.stderr_utf8().contains(needle.as_ref()),
"{}",
format!(
"The stderr {} did not contain the string {}",
"The stderr \"{}\" did not contain the string \"{}\"",
self.stderr_utf8().as_str(),
needle.as_ref(),
needle.as_ref()
)
);
self
Expand Down

0 comments on commit 0c0edce

Please sign in to comment.