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`