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:
Alfredo Garcia 2020-08-04 17:38:39 -03:00 committed by GitHub
parent 78b5bf5e9a
commit e037466e26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -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`