thin-provisioning-tools/tests/common/common_args.rs
Ming-Hung Tsai f395bab7be [tests] Use traits to specify test parameters
To deal with variety in target attributes and their expected outputs,
the test parameters are categorized into traits, thus the test program
could define test parameters in a more structured way, without having
to pass multiple tightly-coupled parameters to test functions.
2021-07-09 01:22:22 +08:00

99 lines
2.0 KiB
Rust

use crate::common::*;
use thinp::version::tools_version;
//------------------------------------------
// help
pub fn test_help_short<'a, P>() -> Result<()>
where
P: Program<'a>,
{
let stdout = run_ok(P::path(), &["-h"])?;
assert_eq!(stdout, P::usage());
Ok(())
}
pub fn test_help_long<'a, P>() -> Result<()>
where
P: Program<'a>,
{
let stdout = run_ok(P::path(), &["--help"])?;
assert_eq!(stdout, P::usage());
Ok(())
}
#[macro_export]
macro_rules! test_accepts_help {
($program: ident) => {
#[test]
fn accepts_h() -> Result<()> {
test_help_short::<$program>()
}
#[test]
fn accepts_help() -> Result<()> {
test_help_long::<$program>()
}
};
}
//------------------------------------------
// version
pub fn test_version_short<'a, P>() -> Result<()>
where
P: Program<'a>,
{
let stdout = run_ok(P::path(), &["-V"])?;
assert!(stdout.contains(tools_version()));
Ok(())
}
pub fn test_version_long<'a, P>() -> Result<()>
where
P: Program<'a>,
{
let stdout = run_ok(P::path(), &["--version"])?;
assert!(stdout.contains(tools_version()));
Ok(())
}
#[macro_export]
macro_rules! test_accepts_version {
($program: ident) => {
#[test]
fn accepts_v() -> Result<()> {
test_version_short::<$program>()
}
#[test]
fn accepts_version() -> Result<()> {
test_version_long::<$program>()
}
};
}
//------------------------------------------
pub fn test_rejects_bad_option<'a, P>() -> Result<()>
where
P: Program<'a>,
{
let option = "--hedgehogs-only";
let stderr = run_fail(P::path(), &[option])?;
assert!(stderr.contains(&P::bad_option_hint(option)));
Ok(())
}
#[macro_export]
macro_rules! test_rejects_bad_option {
($program: ident) => {
#[test]
fn rejects_bad_option() -> Result<()> {
test_rejects_bad_option::<$program>()
}
};
}
//------------------------------------------