HelpTest.cpp
2.56 KB
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
#ifdef CLI_SINGLE_FILE
#include "CLI11.hpp"
#else
#include "CLI/CLI.hpp"
#endif
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include <fstream>
using ::testing::HasSubstr;
TEST(THelp, Basic) {
CLI::App app{"My prog"};
std::string help = app.help();
EXPECT_THAT(help, HasSubstr("My prog"));
EXPECT_THAT(help, HasSubstr("-h,--help"));
EXPECT_THAT(help, HasSubstr("Options:"));
EXPECT_THAT(help, HasSubstr("Usage:"));
}
TEST(THelp, OptionalPositional) {
CLI::App app{"My prog"};
std::string x;
app.add_option("something", x, "My option here");
std::string help = app.help();
EXPECT_THAT(help, HasSubstr("My prog"));
EXPECT_THAT(help, HasSubstr("-h,--help"));
EXPECT_THAT(help, HasSubstr("Options:"));
EXPECT_THAT(help, HasSubstr("Positionals:"));
EXPECT_THAT(help, HasSubstr("something TEXT"));
EXPECT_THAT(help, HasSubstr("My option here"));
EXPECT_THAT(help, HasSubstr("Usage: program [OPTIONS] [something]"));
}
TEST(THelp, OptionalPositionalAndOptions) {
CLI::App app{"My prog"};
app.add_flag("-q,--quick");
std::string x;
app.add_option("something", x, "My option here");
std::string help = app.help();
EXPECT_THAT(help, HasSubstr("My prog"));
EXPECT_THAT(help, HasSubstr("-h,--help"));
EXPECT_THAT(help, HasSubstr("Options:"));
EXPECT_THAT(help, HasSubstr("Usage: program [OPTIONS] [something]"));
}
TEST(THelp, RequiredPositionalAndOptions) {
CLI::App app{"My prog"};
app.add_flag("-q,--quick");
std::string x;
app.add_option("something", x, "My option here")
->required();
std::string help = app.help();
EXPECT_THAT(help, HasSubstr("My prog"));
EXPECT_THAT(help, HasSubstr("-h,--help"));
EXPECT_THAT(help, HasSubstr("Options:"));
EXPECT_THAT(help, HasSubstr("Positionals:"));
EXPECT_THAT(help, HasSubstr("Usage: program [OPTIONS] something"));
}
TEST(THelp, EnvName) {
CLI::App app{"My prog"};
std::string input;
app.add_option("--something", input)->envname("SOME_ENV");
std::string help = app.help();
EXPECT_THAT(help, HasSubstr("SOME_ENV"));
}
TEST(THelp, Requires) {
CLI::App app{"My prog"};
CLI::Option* op1 = app.add_flag("--op1");
app.add_flag("--op2")->requires(op1);
std::string help = app.help();
EXPECT_THAT(help, HasSubstr("Requires: --op1"));
}
TEST(THelp, Excludes) {
CLI::App app{"My prog"};
CLI::Option* op1 = app.add_flag("--op1");
app.add_flag("--op2")->excludes(op1);
std::string help = app.help();
EXPECT_THAT(help, HasSubstr("Excludes: --op1"));
}