summaryrefslogtreecommitdiff
path: root/vendor/bandit/specs/options.spec.cpp
blob: 02e2818cf39cb1ce3e4ca62d9d7ecd1e91a2ff54 (plain)
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
104
105
106
107
108
109
#include <specs/specs.h>

using namespace bandit::specs::util;
namespace bd = bandit::detail;

go_bandit([](){

    describe("options:", [&](){
    
      it("parses the '--help' option", [&](){
        const char* args[] = {"executable", "--help"};
        argv_helper argv(2, args);

        bd::options opt(argv.argc(), argv.argv());

        AssertThat(opt.help(), IsTrue());
      });

      it("parses the '--version' option", [&](){
        const char* args[] = {"executable", "--version"};
        argv_helper argv(2, args);

        bd::options opt(argv.argc(), argv.argv());

        AssertThat(opt.version(), IsTrue());
      });

      it("parses the '--no-color' option", [&](){
        const char* args[] = {"executable", "--no-color"};
        argv_helper argv(2, args);

        bd::options opt(argv.argc(), argv.argv());

        AssertThat(opt.no_color(), IsTrue());
      });

      it("parser the '--formatter=vs' option", [&](){
        const char* args[] = {"executable", "--formatter=vs"};
        argv_helper argv(2, args);

        bd::options opt(argv.argc(), argv.argv());
        AssertThat(opt.formatter(), Equals(bd::options::formatters::FORMATTER_VS));
      });

      it("parser the '--formatter=default' option", [&](){
        const char* args[] = {"executable", "--formatter=default"};
        argv_helper argv(2, args);

        bd::options opt(argv.argc(), argv.argv());
        AssertThat(opt.formatter(), Equals(bd::options::formatters::FORMATTER_DEFAULT));
      });

      it("parses the '--skip=\"substring\"' option", [&](){
        const char* args[] = {"executable", "--skip=substring"};
        argv_helper argv(2, args);

        bd::options opt(argv.argc(), argv.argv());
        AssertThat(opt.skip(), Equals("substring"));
      });

      it("parses skip as empty string if not present", [&](){
        const char* args[] = {"executable"};
        argv_helper argv(1, args);

        bd::options opt(argv.argc(), argv.argv());
        AssertThat(opt.skip(), Equals(""));
      });

      it("parses the '--only=\"substring\"' option", [&](){
        const char* args[] = {"executable", "--only=substring"};
        argv_helper argv(2, args);

        bd::options opt(argv.argc(), argv.argv());
        AssertThat(opt.only(), Equals("substring"));
      });

      it("parses only as empty string if not present", [&](){
        const char* args[] = {"executable"};
        argv_helper argv(1, args);

        bd::options opt(argv.argc(), argv.argv());
        AssertThat(opt.only(), Equals(""));
      });

      describe("with no arguments", [&](){
        const char* args[] = {"executable"};
        argv_helper argv(1, args);
        bd::options opt(argv.argc(), argv.argv());

      
        it("cannot find '--help'", [&](){
          AssertThat(opt.help(), IsFalse());
        });

        it("cannot find '--version'", [&](){
          AssertThat(opt.version(), IsFalse());
        });
      
        it("cannot find '--no-color'", [&](){
          AssertThat(opt.no_color(), IsFalse());
        });

        it("uses default formatter for '--formatter'", [&](){
          AssertThat(opt.formatter(), Equals(bd::options::formatters::FORMATTER_DEFAULT));
        });
      });
    });

});