18 #include "gtest/gtest.h" 28 ABSL_FLAG(
int, usage_reporting_test_flag_01, 101,
29 "usage_reporting_test_flag_01 help message");
30 ABSL_FLAG(
bool, usage_reporting_test_flag_02,
false,
31 "usage_reporting_test_flag_02 help message");
32 ABSL_FLAG(
double, usage_reporting_test_flag_03, 1.03,
33 "usage_reporting_test_flag_03 help message");
34 ABSL_FLAG(int64_t, usage_reporting_test_flag_04, 1000000000000004L,
35 "usage_reporting_test_flag_04 help message");
44 ABSL_FLAG(UDT, usage_reporting_test_flag_05, {},
45 "usage_reporting_test_flag_05 help message");
53 std::string normalized(fname);
54 std::replace(normalized.begin(), normalized.end(),
'\\',
'/');
58 auto absl_pos = fname.
find(
"/absl/");
60 fname = fname.substr(absl_pos + 1);
62 return std::string(fname);
65 class UsageReportingTest :
public testing::Test {
67 UsageReportingTest() {
81 using UsageReportingDeathTest = UsageReportingTest;
83 TEST_F(UsageReportingDeathTest, TestSetProgramUsageMessage) {
89 ".*SetProgramUsageMessage\\(\\) called twice.*");
95 TEST_F(UsageReportingTest, TestFlagHelpHRF_on_flag_01) {
97 std::stringstream test_buf;
102 R
"( -usage_reporting_test_flag_01 (usage_reporting_test_flag_01 help message); 107 TEST_F(UsageReportingTest, TestFlagHelpHRF_on_flag_02) { 109 std::stringstream test_buf;
114 R
"( -usage_reporting_test_flag_02 (usage_reporting_test_flag_02 help message); 119 TEST_F(UsageReportingTest, TestFlagHelpHRF_on_flag_03) { 121 std::stringstream test_buf;
126 R
"( -usage_reporting_test_flag_03 (usage_reporting_test_flag_03 help message); 131 TEST_F(UsageReportingTest, TestFlagHelpHRF_on_flag_04) { 133 std::stringstream test_buf;
138 R
"( -usage_reporting_test_flag_04 (usage_reporting_test_flag_04 help message); 139 default: 1000000000000004; 143 TEST_F(UsageReportingTest, TestFlagHelpHRF_on_flag_05) { 145 std::stringstream test_buf;
150 R
"( -usage_reporting_test_flag_05 (usage_reporting_test_flag_05 help message); 157 TEST_F(UsageReportingTest, TestFlagsHelpHRF) {
158 std::string usage_test_flags_out =
159 R
"(usage_test: Custom usage message 161 Flags from absl/flags/internal/usage_test.cc: 162 -usage_reporting_test_flag_01 (usage_reporting_test_flag_01 help message); 164 -usage_reporting_test_flag_02 (usage_reporting_test_flag_02 help message); 166 -usage_reporting_test_flag_03 (usage_reporting_test_flag_03 help message); 168 -usage_reporting_test_flag_04 (usage_reporting_test_flag_04 help message); 169 default: 1000000000000004; 170 -usage_reporting_test_flag_05 (usage_reporting_test_flag_05 help message); 174 std::stringstream test_buf_01; 176 flags::HelpFormat::kHumanReadable);
177 EXPECT_EQ(test_buf_01.str(), usage_test_flags_out);
179 std::stringstream test_buf_02;
181 flags::HelpFormat::kHumanReadable);
182 EXPECT_EQ(test_buf_02.str(), usage_test_flags_out);
184 std::stringstream test_buf_03;
186 flags::HelpFormat::kHumanReadable);
187 EXPECT_EQ(test_buf_03.str(), usage_test_flags_out);
189 std::stringstream test_buf_04;
191 flags::HelpFormat::kHumanReadable);
192 EXPECT_EQ(test_buf_04.str(),
193 R
"(usage_test: Custom usage message 195 No modules matched: use -helpfull 198 std::stringstream test_buf_05; 200 std::string test_out = test_buf_05.str();
205 test_out_str,
"Flags from absl/flags/internal/usage_test.cc:"));
207 "Flags from absl/flags/internal/usage.cc:"));
216 TEST_F(UsageReportingTest, TestNoUsageFlags) {
217 std::stringstream test_buf;
223 TEST_F(UsageReportingTest, TestUsageFlag_helpshort) {
226 std::stringstream test_buf;
228 EXPECT_EQ(test_buf.str(),
229 R
"(usage_test: Custom usage message 231 Flags from absl/flags/internal/usage_test.cc: 232 -usage_reporting_test_flag_01 (usage_reporting_test_flag_01 help message); 234 -usage_reporting_test_flag_02 (usage_reporting_test_flag_02 help message); 236 -usage_reporting_test_flag_03 (usage_reporting_test_flag_03 help message); 238 -usage_reporting_test_flag_04 (usage_reporting_test_flag_04 help message); 239 default: 1000000000000004; 240 -usage_reporting_test_flag_05 (usage_reporting_test_flag_05 help message); 247 TEST_F(UsageReportingTest, TestUsageFlag_help) {
250 std::stringstream test_buf;
252 EXPECT_EQ(test_buf.str(),
253 R
"(usage_test: Custom usage message 255 Flags from absl/flags/internal/usage_test.cc: 256 -usage_reporting_test_flag_01 (usage_reporting_test_flag_01 help message); 258 -usage_reporting_test_flag_02 (usage_reporting_test_flag_02 help message); 260 -usage_reporting_test_flag_03 (usage_reporting_test_flag_03 help message); 262 -usage_reporting_test_flag_04 (usage_reporting_test_flag_04 help message); 263 default: 1000000000000004; 264 -usage_reporting_test_flag_05 (usage_reporting_test_flag_05 help message); 267 Try --helpfull to get a list of all flags. 273 TEST_F(UsageReportingTest, TestUsageFlag_helppackage) {
276 std::stringstream test_buf;
278 EXPECT_EQ(test_buf.str(),
279 R
"(usage_test: Custom usage message 281 Flags from absl/flags/internal/usage_test.cc: 282 -usage_reporting_test_flag_01 (usage_reporting_test_flag_01 help message); 284 -usage_reporting_test_flag_02 (usage_reporting_test_flag_02 help message); 286 -usage_reporting_test_flag_03 (usage_reporting_test_flag_03 help message); 288 -usage_reporting_test_flag_04 (usage_reporting_test_flag_04 help message); 289 default: 1000000000000004; 290 -usage_reporting_test_flag_05 (usage_reporting_test_flag_05 help message); 293 Try --helpfull to get a list of all flags. 299 TEST_F(UsageReportingTest, TestUsageFlag_version) {
302 std::stringstream test_buf;
305 EXPECT_EQ(test_buf.str(),
306 "usage_test\nDebug build (NDEBUG not #defined)\n");
308 EXPECT_EQ(test_buf.str(),
"usage_test\n");
314 TEST_F(UsageReportingTest, TestUsageFlag_only_check_args) {
317 std::stringstream test_buf;
319 EXPECT_EQ(test_buf.str(),
"");
324 TEST_F(UsageReportingTest, TestUsageFlag_helpon) {
327 std::stringstream test_buf_01;
329 EXPECT_EQ(test_buf_01.str(),
330 R
"(usage_test: Custom usage message 332 No modules matched: use -helpfull 337 std::stringstream test_buf_02;
339 EXPECT_EQ(test_buf_02.str(),
340 R
"(usage_test: Custom usage message 342 Flags from absl/flags/internal/usage_test.cc: 343 -usage_reporting_test_flag_01 (usage_reporting_test_flag_01 help message); 345 -usage_reporting_test_flag_02 (usage_reporting_test_flag_02 help message); 347 -usage_reporting_test_flag_03 (usage_reporting_test_flag_03 help message); 349 -usage_reporting_test_flag_04 (usage_reporting_test_flag_04 help message); 350 default: 1000000000000004; 351 -usage_reporting_test_flag_05 (usage_reporting_test_flag_05 help message); 360 int main(
int argc,
char* argv[]) {
364 ::testing::InitGoogleTest(&argc, argv);
366 return RUN_ALL_TESTS();
void SetProgramUsageMessage(absl::string_view new_usage_message)
void FlagHelp(std::ostream &out, const flags_internal::CommandLineFlag &flag, HelpFormat format)
std::string AbslUnparseFlag(const UDT &)
size_type find(string_view s, size_type pos=0) const noexcept
static constexpr size_type npos
ABSL_FLAG(int, usage_reporting_test_flag_01, 101, "usage_reporting_test_flag_01 help message")
void FlagsHelp(std::ostream &out, absl::string_view filter, HelpFormat format)
void SetFlagsUsageConfig(FlagsUsageConfig usage_config)
TEST_F(GraphCyclesTest, NoCycle)
CommandLineFlag * FindCommandLineFlag(absl::string_view name)
int HandleUsageFlags(std::ostream &out)
int main(int argc, char *argv[])
absl::string_view ProgramUsageMessage()
bool StartsWith(absl::string_view text, absl::string_view prefix)
bool AbslParseFlag(absl::string_view, UDT *, std::string *)
void SetProgramInvocationName(absl::string_view prog_name_str)
T GetFlag(const absl::Flag< T > &flag)
void SetFlag(absl::Flag< T > *flag, const T &v)
bool StrContains(absl::string_view haystack, absl::string_view needle)
std::function< std::string(absl::string_view)> normalize_filename