-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_help.cpp
More file actions
105 lines (97 loc) · 2.91 KB
/
test_help.cpp
File metadata and controls
105 lines (97 loc) · 2.91 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
#include <cfbox/help.hpp>
#include <cfbox/term.hpp>
#include <gtest/gtest.h>
#include <cstdio>
#include <string>
#include "test_capture.hpp"
TEST(HelpTest, PrintHelpContainsName) {
constexpr cfbox::help::HelpEntry entry = {
.name = "testapp",
.version = "1.0",
.one_line = "a test applet",
.usage = "testapp [OPTIONS]",
.options = " -v verbose",
.extra = "",
};
auto out = cfbox::test::capture_stdout([&]()->int {
cfbox::help::print_help(entry);
return 0;
});
EXPECT_NE(out.find("testapp"), std::string::npos);
EXPECT_NE(out.find("a test applet"), std::string::npos);
EXPECT_NE(out.find("testapp [OPTIONS]"), std::string::npos);
EXPECT_NE(out.find("-v"), std::string::npos);
EXPECT_NE(out.find("--help"), std::string::npos);
EXPECT_NE(out.find("--version"), std::string::npos);
}
TEST(HelpTest, PrintHelpWithExtra) {
constexpr cfbox::help::HelpEntry entry = {
.name = "foo",
.version = "0.1",
.one_line = "does foo",
.usage = "foo",
.options = "",
.extra = "Note: foo is experimental",
};
auto out = cfbox::test::capture_stdout([&]()->int {
cfbox::help::print_help(entry);
return 0;
});
EXPECT_NE(out.find("experimental"), std::string::npos);
}
TEST(HelpTest, PrintVersion) {
constexpr cfbox::help::HelpEntry entry = {
.name = "echo",
.version = "0.0.1",
.one_line = "",
.usage = "",
.options = "",
.extra = "",
};
auto out = cfbox::test::capture_stdout([&]()->int {
cfbox::help::print_version(entry);
return 0;
});
EXPECT_NE(out.find("cfbox echo 0.0.1"), std::string::npos);
}
TEST(HelpTest, PrintCfboxVersion) {
auto out = cfbox::test::capture_stdout([&]()->int {
cfbox::help::print_cfbox_version();
return 0;
});
EXPECT_NE(out.find("cfbox"), std::string::npos);
}
TEST(HelpTest, ColorDisabledOutput) {
cfbox::term::set_color_enabled(false);
constexpr cfbox::help::HelpEntry entry = {
.name = "test",
.version = "1.0",
.one_line = "test",
.usage = "test",
.options = "",
.extra = "",
};
auto out = cfbox::test::capture_stdout([&]()->int {
cfbox::help::print_help(entry);
return 0;
});
EXPECT_EQ(out.find("\033["), std::string::npos);
cfbox::term::reset_color_enabled();
}
TEST(HelpTest, ColorEnabledOutput) {
cfbox::term::set_color_enabled(true);
constexpr cfbox::help::HelpEntry entry = {
.name = "test",
.version = "1.0",
.one_line = "test",
.usage = "test",
.options = "",
.extra = "",
};
auto out = cfbox::test::capture_stdout([&]()->int {
cfbox::help::print_help(entry);
return 0;
});
EXPECT_NE(out.find("\033["), std::string::npos);
cfbox::term::reset_color_enabled();
}