18 #include "gtest/gtest.h" 25 ABSL_FLAG(
int, int_flag, 201,
"int_flag help");
26 ABSL_FLAG(std::string, string_flag,
"dflt",
34 class CommandLineFlagTest :
public testing::Test {
36 void SetUp()
override { flag_saver_ = absl::make_unique<flags::FlagSaver>(); }
37 void TearDown()
override { flag_saver_.reset(); }
40 std::unique_ptr<flags::FlagSaver> flag_saver_;
43 TEST_F(CommandLineFlagTest, TestAttributesAccessMethods) {
47 EXPECT_EQ(flag_01->Name(),
"int_flag");
48 EXPECT_EQ(flag_01->Help(),
"int_flag help");
49 EXPECT_EQ(flag_01->Typename(),
"");
50 EXPECT_TRUE(!flag_01->IsRetired());
51 EXPECT_TRUE(flag_01->IsOfType<
int>());
54 "absl/flags/internal/commandlineflag_test.cc"));
59 EXPECT_EQ(flag_02->Name(),
"string_flag");
60 EXPECT_EQ(flag_02->Help(),
"string_flag help");
61 EXPECT_EQ(flag_02->Typename(),
"");
62 EXPECT_TRUE(!flag_02->IsRetired());
63 EXPECT_TRUE(flag_02->IsOfType<std::string>());
66 "absl/flags/internal/commandlineflag_test.cc"));
71 EXPECT_EQ(flag_03->Name(),
"bool_retired_flag");
72 EXPECT_EQ(flag_03->Help(),
"");
73 EXPECT_EQ(flag_03->Typename(),
"");
74 EXPECT_TRUE(flag_03->IsRetired());
75 EXPECT_TRUE(flag_03->IsOfType<
bool>());
76 EXPECT_EQ(flag_03->Filename(),
"RETIRED");
81 TEST_F(CommandLineFlagTest, TestValueAccessMethods) {
86 EXPECT_EQ(flag_01->CurrentValue(),
"301");
87 EXPECT_EQ(flag_01->DefaultValue(),
"201");
93 EXPECT_EQ(flag_02->CurrentValue(),
"new_str_value");
94 EXPECT_EQ(flag_02->DefaultValue(),
"dflt");
99 TEST_F(CommandLineFlagTest, TestSetFromStringCurrentValue) {
103 EXPECT_FALSE(flag_01->on_command_line);
108 EXPECT_FALSE(flag_01->on_command_line);
113 EXPECT_FALSE(flag_01->on_command_line);
118 EXPECT_EQ(err,
"Illegal value 'xyz' specified for flag 'int_flag'");
119 EXPECT_FALSE(flag_01->on_command_line);
124 EXPECT_EQ(err,
"Illegal value 'A1' specified for flag 'int_flag'");
125 EXPECT_FALSE(flag_01->on_command_line);
130 EXPECT_FALSE(flag_01->on_command_line);
135 EXPECT_TRUE(flag_01->on_command_line);
139 EXPECT_EQ(err,
"Illegal value '' specified for flag 'int_flag'");
153 TEST_F(CommandLineFlagTest, TestSetFromStringDefaultValue) {
160 EXPECT_EQ(flag_01->DefaultValue(),
"111");
166 EXPECT_EQ(flag_02->DefaultValue(),
"abc");
171 TEST_F(CommandLineFlagTest, TestSetFromStringIfDefault) {
std::string StrCat(const AlphaNum &a, const AlphaNum &b)
ABSL_FLAG(int, int_flag, 201, "int_flag help")
bool EndsWith(absl::string_view text, absl::string_view suffix)
TEST_F(GraphCyclesTest, NoCycle)
CommandLineFlag * FindCommandLineFlag(absl::string_view name)
ABSL_RETIRED_FLAG(bool, bool_retired_flag, false, "bool_retired_flag help")
T GetFlag(const absl::Flag< T > &flag)
void SetFlag(absl::Flag< T > *flag, const T &v)
CommandLineFlag * FindRetiredFlag(absl::string_view name)