2021-07-20 15:07:55 +05:30
|
|
|
use anyhow::Result;
|
|
|
|
|
2021-07-01 19:57:37 +05:30
|
|
|
use thinp::version::tools_version;
|
|
|
|
|
2021-07-20 15:07:55 +05:30
|
|
|
use crate::common::process::*;
|
|
|
|
use crate::common::program::*;
|
|
|
|
|
2021-07-01 19:57:37 +05:30
|
|
|
//------------------------------------------
|
|
|
|
// help
|
|
|
|
|
2021-07-06 07:21:27 +05:30
|
|
|
pub fn test_help_short<'a, P>() -> Result<()>
|
|
|
|
where
|
|
|
|
P: Program<'a>,
|
|
|
|
{
|
|
|
|
let stdout = run_ok(P::path(), &["-h"])?;
|
|
|
|
assert_eq!(stdout, P::usage());
|
2021-07-01 19:57:37 +05:30
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2021-07-06 07:21:27 +05:30
|
|
|
pub fn test_help_long<'a, P>() -> Result<()>
|
|
|
|
where
|
|
|
|
P: Program<'a>,
|
|
|
|
{
|
|
|
|
let stdout = run_ok(P::path(), &["--help"])?;
|
|
|
|
assert_eq!(stdout, P::usage());
|
2021-07-01 19:57:37 +05:30
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! test_accepts_help {
|
2021-07-06 07:21:27 +05:30
|
|
|
($program: ident) => {
|
2021-07-01 19:57:37 +05:30
|
|
|
#[test]
|
|
|
|
fn accepts_h() -> Result<()> {
|
2021-07-06 07:21:27 +05:30
|
|
|
test_help_short::<$program>()
|
2021-07-01 19:57:37 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn accepts_help() -> Result<()> {
|
2021-07-06 07:21:27 +05:30
|
|
|
test_help_long::<$program>()
|
2021-07-01 19:57:37 +05:30
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------
|
|
|
|
// version
|
|
|
|
|
2021-07-06 07:21:27 +05:30
|
|
|
pub fn test_version_short<'a, P>() -> Result<()>
|
|
|
|
where
|
|
|
|
P: Program<'a>,
|
|
|
|
{
|
|
|
|
let stdout = run_ok(P::path(), &["-V"])?;
|
2021-07-01 19:57:37 +05:30
|
|
|
assert!(stdout.contains(tools_version()));
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2021-07-06 07:21:27 +05:30
|
|
|
pub fn test_version_long<'a, P>() -> Result<()>
|
|
|
|
where
|
|
|
|
P: Program<'a>,
|
|
|
|
{
|
|
|
|
let stdout = run_ok(P::path(), &["--version"])?;
|
2021-07-01 19:57:37 +05:30
|
|
|
assert!(stdout.contains(tools_version()));
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! test_accepts_version {
|
|
|
|
($program: ident) => {
|
|
|
|
#[test]
|
|
|
|
fn accepts_v() -> Result<()> {
|
2021-07-06 07:21:27 +05:30
|
|
|
test_version_short::<$program>()
|
2021-07-01 19:57:37 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn accepts_version() -> Result<()> {
|
2021-07-06 07:21:27 +05:30
|
|
|
test_version_long::<$program>()
|
2021-07-01 19:57:37 +05:30
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------
|
|
|
|
|
2021-07-06 07:21:27 +05:30
|
|
|
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)));
|
2021-07-01 19:57:37 +05:30
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! test_rejects_bad_option {
|
|
|
|
($program: ident) => {
|
|
|
|
#[test]
|
|
|
|
fn rejects_bad_option() -> Result<()> {
|
2021-07-06 07:21:27 +05:30
|
|
|
test_rejects_bad_option::<$program>()
|
2021-07-01 19:57:37 +05:30
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------
|