From 78a381032b953f50780c7c89490cdbda8c05b133 Mon Sep 17 00:00:00 2001 From: Joining7943 <111500881+Joining7943@users.noreply.github.com> Date: Fri, 6 Jan 2023 17:05:59 +0100 Subject: [PATCH] tests/util: Improve assertion messages of `CmdResult::stderr_is_bytes`, `stdout_is_bytes` --- tests/common/util.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/common/util.rs b/tests/common/util.rs index ae1b965ef..7978ed87d 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -474,7 +474,11 @@ impl CmdResult { /// whose bytes equal those of the passed in slice #[track_caller] pub fn stdout_is_bytes>(&self, msg: T) -> &Self { - assert_eq!(self.stdout, msg.as_ref()); + assert_eq!(self.stdout, msg.as_ref(), + "stdout as bytes wasn't equal to expected bytes. Result as strings:\nstdout ='{:?}'\nexpected='{:?}'", + std::str::from_utf8(&self.stdout), + std::str::from_utf8(msg.as_ref()), + ); self } @@ -555,7 +559,13 @@ impl CmdResult { /// whose bytes equal those of the passed in slice #[track_caller] pub fn stderr_is_bytes>(&self, msg: T) -> &Self { - assert_eq!(self.stderr, msg.as_ref()); + assert_eq!( + &self.stderr, + msg.as_ref(), + "stderr as bytes wasn't equal to expected bytes. Result as strings:\nstderr ='{:?}'\nexpected='{:?}'", + std::str::from_utf8(&self.stderr), + std::str::from_utf8(msg.as_ref()) + ); self }