Skip to content

Commit f4387c5

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

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
@@ -108,7 +108,16 @@ 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(),
113+
content.as_ref().trim(),
114+
"{}",
115+
format!(
116+
"The stdout \"{}\" did not equal the string \"{}\"",
117+
self.stdout_utf8().as_str(),
118+
content.as_ref().trim()
119+
)
120+
);
112121
self
113122
}
114123

@@ -121,18 +130,28 @@ impl CompletedProcess {
121130
/// Checks that trimmed `stderr` matches trimmed `content`.
122131
#[track_caller]
123132
pub fn assert_stderr_equals<S: AsRef<str>>(self, content: S) -> Self {
124-
assert_eq!(self.stderr_utf8().trim(), content.as_ref().trim());
133+
assert_eq!(
134+
self.stderr_utf8().trim(),
135+
content.as_ref().trim(),
136+
"{}",
137+
format!(
138+
"The stderr \"{}\" did not equal the string \"{}\"",
139+
self.stderr_utf8().as_str(),
140+
content.as_ref().trim()
141+
)
142+
);
125143
self
126144
}
127145

128146
#[track_caller]
129147
pub fn assert_stderr_contains<S: AsRef<str>>(self, needle: S) -> Self {
130148
assert!(
131149
self.stderr_utf8().contains(needle.as_ref()),
150+
"{}",
132151
format!(
133-
"The stderr {} did not contain the string {}",
152+
"The stderr \"{}\" did not contain the string \"{}\"",
134153
self.stderr_utf8().as_str(),
135-
needle.as_ref(),
154+
needle.as_ref()
136155
)
137156
);
138157
self

0 commit comments

Comments
 (0)