Make more checks in non server acceptance tests (#860)
* make sure no info is printed in non server tests * check exact full output for validity instead of log msgs * add end of output character to version regex * use coercions, use equality operator Co-authored-by: Jane Lusby <jlusby42@gmail.com> Co-authored-by: Jane Lusby <jlusby42@gmail.com>
This commit is contained in:
parent
9c387521bd
commit
c9093e4d59
|
@ -223,7 +223,7 @@ impl TestOutput {
|
|||
|
||||
pub fn stdout_contains(&self, regex: &str) -> Result<&Self> {
|
||||
let re = regex::Regex::new(regex)?;
|
||||
let stdout = String::from_utf8_lossy(self.output.stdout.as_slice());
|
||||
let stdout = String::from_utf8_lossy(&self.output.stdout);
|
||||
|
||||
for line in stdout.lines() {
|
||||
if re.is_match(line) {
|
||||
|
@ -241,6 +241,37 @@ impl TestOutput {
|
|||
.with_section(stdout)
|
||||
}
|
||||
|
||||
pub fn stdout_equals(&self, s: &str) -> Result<&Self> {
|
||||
let stdout = String::from_utf8_lossy(&self.output.stdout);
|
||||
|
||||
if stdout == s {
|
||||
return Ok(self);
|
||||
}
|
||||
|
||||
let command = || self.cmd.clone().header("Command:");
|
||||
let stdout = || stdout.into_owned().header("Stdout:");
|
||||
|
||||
Err(eyre!("stdout of command is not equal the given string"))
|
||||
.with_section(command)
|
||||
.with_section(stdout)
|
||||
}
|
||||
|
||||
pub fn stdout_matches(&self, regex: &str) -> Result<&Self> {
|
||||
let re = regex::Regex::new(regex)?;
|
||||
let stdout = String::from_utf8_lossy(&self.output.stdout);
|
||||
|
||||
if re.is_match(&stdout) {
|
||||
return Ok(self);
|
||||
}
|
||||
|
||||
let command = || self.cmd.clone().header("Command:");
|
||||
let stdout = || stdout.into_owned().header("Stdout:");
|
||||
|
||||
Err(eyre!("stdout of command is not equal to the given regex"))
|
||||
.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)]
|
||||
|
|
|
@ -29,6 +29,7 @@ fn generate_no_args() -> Result<()> {
|
|||
let output = child.wait_with_output()?;
|
||||
let output = output.assert_success()?;
|
||||
|
||||
// First line
|
||||
output.stdout_contains(r"# Default configuration for zebrad.")?;
|
||||
|
||||
Ok(())
|
||||
|
@ -71,6 +72,10 @@ fn help_no_args() -> Result<()> {
|
|||
let output = child.wait_with_output()?;
|
||||
let output = output.assert_success()?;
|
||||
|
||||
// First line haves the version
|
||||
output.stdout_contains(r"zebrad [0-9].[0-9].[0-9]")?;
|
||||
|
||||
// Make sure we are in help by looking usage string
|
||||
output.stdout_contains(r"USAGE:")?;
|
||||
|
||||
Ok(())
|
||||
|
@ -102,7 +107,7 @@ fn revhex_args() -> Result<()> {
|
|||
let output = child.wait_with_output()?;
|
||||
let output = output.assert_success()?;
|
||||
|
||||
output.stdout_contains(r"55ffee33")?;
|
||||
output.stdout_equals("55ffee33\n")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -213,7 +218,7 @@ fn version_no_args() -> Result<()> {
|
|||
let output = child.wait_with_output()?;
|
||||
let output = output.assert_success()?;
|
||||
|
||||
output.stdout_contains(r"zebrad [0-9].[0-9].[0-9]")?;
|
||||
output.stdout_matches(r"^zebrad [0-9].[0-9].[0-9]-[A-Za-z]*.[0-9]\n$")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue