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 23:41:46 +05:30
|
|
|
use crate::args;
|
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>,
|
|
|
|
{
|
2021-10-11 16:37:26 +05:30
|
|
|
let stdout = run_ok(P::cmd(args!["-h"]))?;
|
2021-07-06 07:21:27 +05:30
|
|
|
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>,
|
|
|
|
{
|
2021-10-11 16:37:26 +05:30
|
|
|
let stdout = run_ok(P::cmd(vec!["--help"]))?;
|
2021-07-06 07:21:27 +05:30
|
|
|
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>,
|
|
|
|
{
|
2021-10-11 16:37:26 +05:30
|
|
|
let stdout = run_ok(P::cmd(args!["-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>,
|
|
|
|
{
|
2021-10-11 16:37:26 +05:30
|
|
|
let stdout = run_ok(P::cmd(args!["--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";
|
2021-10-11 16:37:26 +05:30
|
|
|
let stderr = run_fail(P::cmd(args![option]))?;
|
2021-07-06 07:21:27 +05:30
|
|
|
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
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------
|