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
This commit is contained in:
parent
78b5bf5e9a
commit
e037466e26
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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`
|
||||
|
|
|
|||
Loading…
Reference in New Issue