Skip to content

Commit 0c0edce

Browse files
committed
make assert_stderr_contains print its contents on panic
1 parent 1b55ff2 commit 0c0edce

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

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

+23-4
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,16 @@ impl CompletedProcess {
163163
/// Checks that trimmed `stdout` matches trimmed `content`.
164164
#[track_caller]
165165
pub fn assert_stdout_equals<S: AsRef<str>>(&self, content: S) -> &Self {
166-
assert_eq!(self.stdout_utf8().trim(), content.as_ref().trim());
166+
assert_eq!(
167+
self.stdout_utf8().trim(),
168+
content.as_ref().trim(),
169+
"{}",
170+
format!(
171+
"The stdout \"{}\" did not equal the string \"{}\"",
172+
self.stdout_utf8().as_str(),
173+
content.as_ref().trim()
174+
)
175+
);
167176
self
168177
}
169178

@@ -176,18 +185,28 @@ impl CompletedProcess {
176185
/// Checks that trimmed `stderr` matches trimmed `content`.
177186
#[track_caller]
178187
pub fn assert_stderr_equals<S: AsRef<str>>(&self, content: S) -> &Self {
179-
assert_eq!(self.stderr_utf8().trim(), content.as_ref().trim());
188+
assert_eq!(
189+
self.stderr_utf8().trim(),
190+
content.as_ref().trim(),
191+
"{}",
192+
format!(
193+
"The stderr \"{}\" did not equal the string \"{}\"",
194+
self.stderr_utf8().as_str(),
195+
content.as_ref().trim()
196+
)
197+
);
180198
self
181199
}
182200

183201
#[track_caller]
184202
pub fn assert_stderr_contains<S: AsRef<str>>(&self, needle: S) -> &Self {
185203
assert!(
186204
self.stderr_utf8().contains(needle.as_ref()),
205+
"{}",
187206
format!(
188-
"The stderr {} did not contain the string {}",
207+
"The stderr \"{}\" did not contain the string \"{}\"",
189208
self.stderr_utf8().as_str(),
190-
needle.as_ref(),
209+
needle.as_ref()
191210
)
192211
);
193212
self

0 commit comments

Comments
 (0)