Skip to content

Commit 75f8428

Browse files
committed
make assert_stderr_contains print its contents on panic
1 parent b6c348f commit 75f8428

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/tools/run-make-support/src/command.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ impl CompletedProcess {
108108
/// Checks that trimmed `stdout` matches trimmed `content`.
109109
#[track_caller]
110110
pub fn assert_stdout_equals<S: AsRef<str>>(self, content: S) -> Self {
111-
assert_eq!(self.stdout_utf8().trim(), content.as_ref().trim());
111+
assert_eq!(
112+
self.stdout_utf8().trim(), content.as_ref().trim()
113+
"{}", format!("The stdout \"{}\" did not equal the string \"{}\"", self.stdout_utf8().as_str(), content.as_ref().trim())
114+
);
112115
self
113116
}
114117

@@ -121,18 +124,28 @@ impl CompletedProcess {
121124
/// Checks that trimmed `stderr` matches trimmed `content`.
122125
#[track_caller]
123126
pub fn assert_stderr_equals<S: AsRef<str>>(self, content: S) -> Self {
124-
assert_eq!(self.stderr_utf8().trim(), content.as_ref().trim());
127+
assert_eq!(
128+
self.stderr_utf8().trim(),
129+
content.as_ref().trim(),
130+
"{}",
131+
format!(
132+
"The stderr \"{}\" did not equal the string \"{}\"",
133+
self.stderr_utf8().as_str(),
134+
content.as_ref().trim()
135+
)
136+
);
125137
self
126138
}
127139

128140
#[track_caller]
129141
pub fn assert_stderr_contains<S: AsRef<str>>(self, needle: S) -> Self {
130142
assert!(
131143
self.stderr_utf8().contains(needle.as_ref()),
144+
"{}",
132145
format!(
133-
"The stderr {} did not contain the string {}",
146+
"The stderr \"{}\" did not contain the string \"{}\"",
134147
self.stderr_utf8().as_str(),
135-
needle.as_ref(),
148+
needle.as_ref()
136149
)
137150
);
138151
self

0 commit comments

Comments
 (0)