From e037466e263ee9850cd6ae273a37844963054969 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Tue, 4 Aug 2020 17:38:39 -0300 Subject: [PATCH] Acceptance tests - check kill signal (#814) * check kill signal exit code * change names and add docs * change exit_status() to was_killed() * change assert calls --- zebra-test/src/command.rs | 12 ++++++++++++ zebrad/tests/acceptance.rs | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/zebra-test/src/command.rs b/zebra-test/src/command.rs index 35988b12..5bb9b545 100644 --- a/zebra-test/src/command.rs +++ b/zebra-test/src/command.rs @@ -6,6 +6,9 @@ use std::process::{Child, Command, ExitStatus, Output}; use std::{env, fs}; use tempdir::TempDir; +#[cfg(unix)] +use std::os::unix::process::ExitStatusExt; + /// Runs a command in a TempDir pub fn test_cmd(path: &str) -> Result<(Command, impl Drop)> { let dir = TempDir::new(path)?; @@ -226,4 +229,13 @@ impl TestOutput { .with_section(command) .with_section(stdout) } + + /// Returns true if the program was killed, false if exit was by another reason. + pub fn was_killed(&self) -> bool { + #[cfg(unix)] + return self.output.status.signal() == Some(9); + + #[cfg(not(unix))] + return self.output.status.code() == Some(1); + } } diff --git a/zebrad/tests/acceptance.rs b/zebrad/tests/acceptance.rs index eb491a4e..ebd86855 100644 --- a/zebrad/tests/acceptance.rs +++ b/zebrad/tests/acceptance.rs @@ -147,6 +147,9 @@ fn seed_no_args() -> Result<()> { output.stdout_contains(r"Starting zebrad in seed mode")?; + // Make sure the command was killed + assert!(output.was_killed()); + Ok(()) } @@ -186,6 +189,9 @@ fn start_no_args() -> Result<()> { output.stdout_contains(r"Starting zebrad")?; + // Make sure the command was killed + assert!(output.was_killed()); + Ok(()) } @@ -198,6 +204,10 @@ fn start_args() -> Result<()> { std::thread::sleep(Duration::from_secs(1)); child.kill()?; let output = child.wait_with_output()?; + + // Make sure the command was killed + assert!(output.was_killed()); + output.assert_failure()?; // unrecognized option `-f`