File: common_args.rs

package info (click to toggle)
thin-provisioning-tools 1.1.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,300 kB
  • sloc: xml: 544; sh: 521; makefile: 133
file content (103 lines) | stat: -rw-r--r-- 2,135 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
use anyhow::Result;

use thinp::tools_version;

use crate::args;
use crate::common::process::*;
use crate::common::program::*;

//------------------------------------------
// help

pub fn test_help_short<'a, P>() -> Result<()>
where
    P: Program<'a>,
{
    let stdout = run_ok(P::cmd(args!["-h"]))?;
    assert_eq!(stdout, P::usage());
    Ok(())
}

pub fn test_help_long<'a, P>() -> Result<()>
where
    P: Program<'a>,
{
    let stdout = run_ok(P::cmd(vec!["--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::cmd(args!["-V"]))?;
    assert!(stdout.starts_with(tools_version!()));
    Ok(())
}

pub fn test_version_long<'a, P>() -> Result<()>
where
    P: Program<'a>,
{
    let stdout = run_ok(P::cmd(args!["--version"]))?;
    assert!(stdout.starts_with(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::cmd(args![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>()
        }
    };
}

//------------------------------------------