16 #include "absl/flags/internal/usage.h"
23 #include "gmock/gmock.h"
24 #include "gtest/gtest.h"
25 #include "absl/flags/flag.h"
26 #include "absl/flags/internal/parse.h"
27 #include "absl/flags/internal/path_util.h"
28 #include "absl/flags/internal/program_name.h"
29 #include "absl/flags/reflection.h"
30 #include "absl/flags/usage.h"
31 #include "absl/flags/usage_config.h"
32 #include "absl/strings/match.h"
33 #include "absl/strings/string_view.h"
35 ABSL_FLAG(
int, usage_reporting_test_flag_01, 101,
36 "usage_reporting_test_flag_01 help message");
37 ABSL_FLAG(
bool, usage_reporting_test_flag_02,
false,
38 "usage_reporting_test_flag_02 help message");
39 ABSL_FLAG(
double, usage_reporting_test_flag_03, 1.03,
40 "usage_reporting_test_flag_03 help message");
42 "usage_reporting_test_flag_04 help message");
56 ABSL_FLAG(UDT, usage_reporting_test_flag_05, {},
57 "usage_reporting_test_flag_05 help message");
61 "usage_reporting_test_flag_06 help message.\n"
64 "Even more long long long long long long long long long long long long "
74 std::replace(normalized.begin(), normalized.end(),
'\\',
'/');
78 auto absl_pos = fname.
rfind(
"absl/");
80 fname = fname.
substr(absl_pos);
87 UsageReportingTest() {
94 ~UsageReportingTest()
override {
106 using UsageReportingDeathTest = UsageReportingTest;
108 TEST_F(UsageReportingDeathTest, TestSetProgramUsageMessage) {
109 #if !defined(GTEST_HAS_ABSL) || !GTEST_HAS_ABSL
116 "This program contains tests written using Google Test"));
126 TEST_F(UsageReportingTest, TestFlagHelpHRF_on_flag_01) {
133 R
"( --usage_reporting_test_flag_01 (usage_reporting_test_flag_01 help message);
138 TEST_F(UsageReportingTest, TestFlagHelpHRF_on_flag_02) {
145 R
"( --usage_reporting_test_flag_02 (usage_reporting_test_flag_02 help message);
150 TEST_F(UsageReportingTest, TestFlagHelpHRF_on_flag_03) {
157 R
"( --usage_reporting_test_flag_03 (usage_reporting_test_flag_03 help message);
162 TEST_F(UsageReportingTest, TestFlagHelpHRF_on_flag_04) {
169 R
"( --usage_reporting_test_flag_04 (usage_reporting_test_flag_04 help message);
170 default: 1000000000000004;
174 TEST_F(UsageReportingTest, TestFlagHelpHRF_on_flag_05) {
181 R
"( --usage_reporting_test_flag_05 (usage_reporting_test_flag_05 help message);
188 TEST_F(UsageReportingTest, TestFlagsHelpHRF) {
190 R
"(usage_test: Custom usage message
192 Flags from absl/flags/internal/usage_test.cc:
193 --usage_reporting_test_flag_01 (usage_reporting_test_flag_01 help message);
195 --usage_reporting_test_flag_02 (usage_reporting_test_flag_02 help message);
197 --usage_reporting_test_flag_03 (usage_reporting_test_flag_03 help message);
199 --usage_reporting_test_flag_04 (usage_reporting_test_flag_04 help message);
200 default: 1000000000000004;
201 --usage_reporting_test_flag_05 (usage_reporting_test_flag_05 help message);
203 --usage_reporting_test_flag_06 (usage_reporting_test_flag_06 help message.
206 Even more long long long long long long long long long long long long help
207 message.); default: "";
209 Try --helpfull to get a list of all flags or --help=substring shows help for
210 flags which include specified substring in either in the name, or description or
214 std::stringstream test_buf_01;
217 EXPECT_EQ(test_buf_01.str(), usage_test_flags_out);
219 std::stringstream test_buf_02;
222 EXPECT_EQ(test_buf_02.str(), usage_test_flags_out);
224 std::stringstream test_buf_03;
225 flags::FlagsHelp(test_buf_03,
"usage_test", flags::HelpFormat::kHumanReadable,
227 EXPECT_EQ(test_buf_03.str(), usage_test_flags_out);
229 std::stringstream test_buf_04;
233 R
"(usage_test: Custom usage message
237 Try --helpfull to get a list of all flags or --help=substring shows help for
238 flags which include specified substring in either in the name, or description or
242 std::stringstream test_buf_05;
250 test_out_str,
"Flags from absl/flags/internal/usage_test.cc:"));
257 TEST_F(UsageReportingTest, TestNoUsageFlags) {
264 TEST_F(UsageReportingTest, TestUsageFlag_helpshort) {
270 R
"(usage_test: Custom usage message
272 Flags from absl/flags/internal/usage_test.cc:
273 --usage_reporting_test_flag_01 (usage_reporting_test_flag_01 help message);
275 --usage_reporting_test_flag_02 (usage_reporting_test_flag_02 help message);
277 --usage_reporting_test_flag_03 (usage_reporting_test_flag_03 help message);
279 --usage_reporting_test_flag_04 (usage_reporting_test_flag_04 help message);
280 default: 1000000000000004;
281 --usage_reporting_test_flag_05 (usage_reporting_test_flag_05 help message);
283 --usage_reporting_test_flag_06 (usage_reporting_test_flag_06 help message.
286 Even more long long long long long long long long long long long long help
287 message.); default: "";
289 Try --helpfull to get a list of all flags or --help=substring shows help for
290 flags which include specified substring in either in the name, or description or
297 TEST_F(UsageReportingTest, TestUsageFlag_help_simple) {
303 R
"(usage_test: Custom usage message
305 Flags from absl/flags/internal/usage_test.cc:
306 --usage_reporting_test_flag_01 (usage_reporting_test_flag_01 help message);
308 --usage_reporting_test_flag_02 (usage_reporting_test_flag_02 help message);
310 --usage_reporting_test_flag_03 (usage_reporting_test_flag_03 help message);
312 --usage_reporting_test_flag_04 (usage_reporting_test_flag_04 help message);
313 default: 1000000000000004;
314 --usage_reporting_test_flag_05 (usage_reporting_test_flag_05 help message);
316 --usage_reporting_test_flag_06 (usage_reporting_test_flag_06 help message.
319 Even more long long long long long long long long long long long long help
320 message.); default: "";
322 Try --helpfull to get a list of all flags or --help=substring shows help for
323 flags which include specified substring in either in the name, or description or
330 TEST_F(UsageReportingTest, TestUsageFlag_help_one_flag) {
337 R
"(usage_test: Custom usage message
339 Flags from absl/flags/internal/usage_test.cc:
340 --usage_reporting_test_flag_06 (usage_reporting_test_flag_06 help message.
343 Even more long long long long long long long long long long long long help
344 message.); default: "";
346 Try --helpfull to get a list of all flags or --help=substring shows help for
347 flags which include specified substring in either in the name, or description or
354 TEST_F(UsageReportingTest, TestUsageFlag_help_multiple_flag) {
361 R
"(usage_test: Custom usage message
363 Flags from absl/flags/internal/usage_test.cc:
364 --usage_reporting_test_flag_01 (usage_reporting_test_flag_01 help message);
366 --usage_reporting_test_flag_02 (usage_reporting_test_flag_02 help message);
368 --usage_reporting_test_flag_03 (usage_reporting_test_flag_03 help message);
370 --usage_reporting_test_flag_04 (usage_reporting_test_flag_04 help message);
371 default: 1000000000000004;
372 --usage_reporting_test_flag_05 (usage_reporting_test_flag_05 help message);
374 --usage_reporting_test_flag_06 (usage_reporting_test_flag_06 help message.
377 Even more long long long long long long long long long long long long help
378 message.); default: "";
380 Try --helpfull to get a list of all flags or --help=substring shows help for
381 flags which include specified substring in either in the name, or description or
388 TEST_F(UsageReportingTest, TestUsageFlag_helppackage) {
394 R
"(usage_test: Custom usage message
396 Flags from absl/flags/internal/usage_test.cc:
397 --usage_reporting_test_flag_01 (usage_reporting_test_flag_01 help message);
399 --usage_reporting_test_flag_02 (usage_reporting_test_flag_02 help message);
401 --usage_reporting_test_flag_03 (usage_reporting_test_flag_03 help message);
403 --usage_reporting_test_flag_04 (usage_reporting_test_flag_04 help message);
404 default: 1000000000000004;
405 --usage_reporting_test_flag_05 (usage_reporting_test_flag_05 help message);
407 --usage_reporting_test_flag_06 (usage_reporting_test_flag_06 help message.
410 Even more long long long long long long long long long long long long help
411 message.); default: "";
413 Try --helpfull to get a list of all flags or --help=substring shows help for
414 flags which include specified substring in either in the name, or description or
421 TEST_F(UsageReportingTest, TestUsageFlag_version) {
435 TEST_F(UsageReportingTest, TestUsageFlag_only_check_args) {
445 TEST_F(UsageReportingTest, TestUsageFlag_helpon) {
449 std::stringstream test_buf_01;
452 R
"(usage_test: Custom usage message
456 Try --helpfull to get a list of all flags or --help=substring shows help for
457 flags which include specified substring in either in the name, or description or
463 std::stringstream test_buf_02;
466 R
"(usage_test: Custom usage message
468 Flags from absl/flags/internal/usage_test.cc:
469 --usage_reporting_test_flag_01 (usage_reporting_test_flag_01 help message);
471 --usage_reporting_test_flag_02 (usage_reporting_test_flag_02 help message);
473 --usage_reporting_test_flag_03 (usage_reporting_test_flag_03 help message);
475 --usage_reporting_test_flag_04 (usage_reporting_test_flag_04 help message);
476 default: 1000000000000004;
477 --usage_reporting_test_flag_05 (usage_reporting_test_flag_05 help message);
479 --usage_reporting_test_flag_06 (usage_reporting_test_flag_06 help message.
482 Even more long long long long long long long long long long long long help
483 message.); default: "";
485 Try --helpfull to get a list of all flags or --help=substring shows help for
486 flags which include specified substring in either in the name, or description or
495 int main(
int argc,
char* argv[]) {
498 #if !defined(GTEST_HAS_ABSL) || !GTEST_HAS_ABSL