From f4387c540466973e2aaff5d0cbd03eb2c6e9ce61 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Sun, 9 Jun 2024 16:43:24 -0400 Subject: [PATCH] make assert_stderr_contains print its contents on panic --- src/tools/run-make-support/src/command.rs | 27 +++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/tools/run-make-support/src/command.rs b/src/tools/run-make-support/src/command.rs index 2d2a6503ef8be..d5363b028fedf 100644 --- a/src/tools/run-make-support/src/command.rs +++ b/src/tools/run-make-support/src/command.rs @@ -108,7 +108,16 @@ impl CompletedProcess { /// Checks that trimmed `stdout` matches trimmed `content`. #[track_caller] pub fn assert_stdout_equals>(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 } @@ -121,7 +130,16 @@ impl CompletedProcess { /// Checks that trimmed `stderr` matches trimmed `content`. #[track_caller] pub fn assert_stderr_equals>(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 } @@ -129,10 +147,11 @@ impl CompletedProcess { pub fn assert_stderr_contains>(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