From d4915c18e787513fc59baefaf5e8d6d40b1f953b Mon Sep 17 00:00:00 2001 From: teor Date: Sat, 20 Feb 2021 06:26:00 +1000 Subject: [PATCH] Fix inverted was_killed logic (#1779) Also improve the error messages and code structure. --- zebra-test/src/command.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/zebra-test/src/command.rs b/zebra-test/src/command.rs index 1e5fe56e..119272f4 100644 --- a/zebra-test/src/command.rs +++ b/zebra-test/src/command.rs @@ -490,30 +490,36 @@ impl TestOutput { /// reason. pub fn assert_was_killed(&self) -> Result<()> { if self.was_killed() { - Err(eyre!("command was killed")).context_from(self)? + Ok(()) + } else { + Err(eyre!( + "command exited without a kill, but the test expected kill exit" + )) + .context_from(self)? } - - Ok(()) } /// Returns Ok if the program was not killed, Err(Report) if exit was by /// another reason. pub fn assert_was_not_killed(&self) -> Result<()> { - if !self.was_killed() { - Err(eyre!("command wasn't killed")).context_from(self)? + if self.was_killed() { + Err(eyre!( + "command was killed, but the test expected an exit without a kill" + )) + .context_from(self)? + } else { + Ok(()) } - - Ok(()) } #[cfg(not(unix))] fn was_killed(&self) -> bool { - self.output.status.code() != Some(1) + self.output.status.code() == Some(1) } #[cfg(unix)] fn was_killed(&self) -> bool { - self.output.status.signal() != Some(9) + self.output.status.signal() == Some(9) } }