diff options
author | Abseil Team <absl-team@google.com> | 2020-04-22 10:52:29 -0700 |
---|---|---|
committer | Derek Mauro <dmauro@google.com> | 2020-04-22 18:03:15 +0000 |
commit | 902909a430e2558ad446294159af39bf019a1ef6 (patch) | |
tree | 1efe99ef701d2afad97677797e977cdac40cce50 /absl/flags | |
parent | cb52b05ea20e8d196f17b45a420c2d323e401324 (diff) |
Export of internal Abseil changes
--
692d3df279e7592d01c1008cb85f2a010c3d17da by Abseil Team <absl-team@google.com>:
Use EXPECT_DEATH_IF_SUPPORTED instead of raw EXPECT_DEATH.
PiperOrigin-RevId: 307802196
--
ebc40936b677b79cad9f87f944794c35946f9dbd by Gennadiy Rozental <rogeeff@google.com>:
Eliminate SetCallback from absl::Flag<T> public interface.
We also make SetCallback on FlagRegistrar to return rvalue, so that we can add more tail calls after it.
PiperOrigin-RevId: 307745935
GitOrigin-RevId: 15f69a9dae9c70c884ce85ca1a4bf359a2609db0
Change-Id: Ibec13463e44e4071c48fb12389f47e716cee7a9d
Diffstat (limited to 'absl/flags')
-rw-r--r-- | absl/flags/flag.h | 3 | ||||
-rw-r--r-- | absl/flags/flag_test.cc | 23 | ||||
-rw-r--r-- | absl/flags/internal/flag.h | 7 | ||||
-rw-r--r-- | absl/flags/internal/usage_test.cc | 5 | ||||
-rw-r--r-- | absl/flags/parse_test.cc | 39 |
5 files changed, 39 insertions, 38 deletions
diff --git a/absl/flags/flag.h b/absl/flags/flag.h index 15061592..194a9d31 100644 --- a/absl/flags/flag.h +++ b/absl/flags/flag.h @@ -149,9 +149,6 @@ class Flag { } T Get() const { return GetImpl()->Get(); } void Set(const T& v) { GetImpl()->Set(v); } - void SetCallback(const flags_internal::FlagCallbackFunc mutation_callback) { - GetImpl()->SetCallback(mutation_callback); - } void InvokeCallback() { GetImpl()->InvokeCallback(); } // The data members are logically private, but they need to be public for diff --git a/absl/flags/flag_test.cc b/absl/flags/flag_test.cc index dbe94a2c..6fa178f1 100644 --- a/absl/flags/flag_test.cc +++ b/absl/flags/flag_test.cc @@ -583,18 +583,21 @@ using FlagDeathTest = FlagTest; TEST_F(FlagDeathTest, TestTypeMismatchValidations) { #if !defined(NDEBUG) - EXPECT_DEATH(static_cast<void>(absl::GetFlag(FLAGS_mistyped_int_flag)), - "Flag 'mistyped_int_flag' is defined as one type and declared " - "as another"); - EXPECT_DEATH(static_cast<void>(absl::GetFlag(FLAGS_mistyped_string_flag)), - "Flag 'mistyped_string_flag' is defined as one type and " - "declared as another"); + EXPECT_DEATH_IF_SUPPORTED( + static_cast<void>(absl::GetFlag(FLAGS_mistyped_int_flag)), + "Flag 'mistyped_int_flag' is defined as one type and declared " + "as another"); + EXPECT_DEATH_IF_SUPPORTED( + static_cast<void>(absl::GetFlag(FLAGS_mistyped_string_flag)), + "Flag 'mistyped_string_flag' is defined as one type and " + "declared as another"); #endif - EXPECT_DEATH(absl::SetFlag(&FLAGS_mistyped_int_flag, 1), - "Flag 'mistyped_int_flag' is defined as one type and declared " - "as another"); - EXPECT_DEATH( + EXPECT_DEATH_IF_SUPPORTED( + absl::SetFlag(&FLAGS_mistyped_int_flag, 1), + "Flag 'mistyped_int_flag' is defined as one type and declared " + "as another"); + EXPECT_DEATH_IF_SUPPORTED( absl::SetFlag(&FLAGS_mistyped_string_flag, std::vector<std::string>{}), "Flag 'mistyped_string_flag' is defined as one type and declared as " "another"); diff --git a/absl/flags/internal/flag.h b/absl/flags/internal/flag.h index 2ae3dce3..6da25aa9 100644 --- a/absl/flags/internal/flag.h +++ b/absl/flags/internal/flag.h @@ -556,9 +556,6 @@ class Flag { impl_.AssertValidType(base_internal::FastTypeId<T>(), &GenRuntimeTypeId<T>); impl_.Write(&v); } - void SetCallback(const FlagCallbackFunc mutation_callback) { - impl_.SetCallback(mutation_callback); - } // CommandLineFlag interface absl::string_view Name() const { return impl_.Name(); } @@ -651,8 +648,8 @@ class FlagRegistrar { if (do_register) flags_internal::RegisterCommandLineFlag(&flag_->impl_); } - FlagRegistrar& OnUpdate(FlagCallbackFunc cb) && { - flag_->SetCallback(cb); + FlagRegistrar OnUpdate(FlagCallbackFunc cb) && { + flag_->impl_.SetCallback(cb); return *this; } diff --git a/absl/flags/internal/usage_test.cc b/absl/flags/internal/usage_test.cc index e1e57e55..8dd3532e 100644 --- a/absl/flags/internal/usage_test.cc +++ b/absl/flags/internal/usage_test.cc @@ -103,8 +103,9 @@ TEST_F(UsageReportingDeathTest, TestSetProgramUsageMessage) { #ifndef _WIN32 // TODO(rogeeff): figure out why this does not work on Windows. - EXPECT_DEATH(absl::SetProgramUsageMessage("custom usage message"), - ".*SetProgramUsageMessage\\(\\) called twice.*"); + EXPECT_DEATH_IF_SUPPORTED( + absl::SetProgramUsageMessage("custom usage message"), + ".*SetProgramUsageMessage\\(\\) called twice.*"); #endif } diff --git a/absl/flags/parse_test.cc b/absl/flags/parse_test.cc index 6f49377a..065f757a 100644 --- a/absl/flags/parse_test.cc +++ b/absl/flags/parse_test.cc @@ -481,21 +481,22 @@ TEST_F(ParseDeathTest, TestUndefinedArg) { "testbin", "--undefined_flag", }; - EXPECT_DEATH(InvokeParse(in_args1), - "Unknown command line flag 'undefined_flag'"); + EXPECT_DEATH_IF_SUPPORTED(InvokeParse(in_args1), + "Unknown command line flag 'undefined_flag'"); const char* in_args2[] = { "testbin", "--noprefixed_flag", }; - EXPECT_DEATH(InvokeParse(in_args2), - "Unknown command line flag 'noprefixed_flag'"); + EXPECT_DEATH_IF_SUPPORTED(InvokeParse(in_args2), + "Unknown command line flag 'noprefixed_flag'"); const char* in_args3[] = { "testbin", "--Int_flag=1", }; - EXPECT_DEATH(InvokeParse(in_args3), "Unknown command line flag 'Int_flag'"); + EXPECT_DEATH_IF_SUPPORTED(InvokeParse(in_args3), + "Unknown command line flag 'Int_flag'"); } // -------------------------------------------------------------------- @@ -505,7 +506,7 @@ TEST_F(ParseDeathTest, TestInvalidBoolFlagFormat) { "testbin", "--bool_flag=", }; - EXPECT_DEATH( + EXPECT_DEATH_IF_SUPPORTED( InvokeParse(in_args1), "Missing the value after assignment for the boolean flag 'bool_flag'"); @@ -513,7 +514,7 @@ TEST_F(ParseDeathTest, TestInvalidBoolFlagFormat) { "testbin", "--nobool_flag=true", }; - EXPECT_DEATH(InvokeParse(in_args2), + EXPECT_DEATH_IF_SUPPORTED(InvokeParse(in_args2), "Negative form with assignment is not valid for the boolean " "flag 'bool_flag'"); } @@ -525,14 +526,14 @@ TEST_F(ParseDeathTest, TestInvalidNonBoolFlagFormat) { "testbin", "--nostring_flag", }; - EXPECT_DEATH(InvokeParse(in_args1), + EXPECT_DEATH_IF_SUPPORTED(InvokeParse(in_args1), "Negative form is not valid for the flag 'string_flag'"); const char* in_args2[] = { "testbin", "--int_flag", }; - EXPECT_DEATH(InvokeParse(in_args2), + EXPECT_DEATH_IF_SUPPORTED(InvokeParse(in_args2), "Missing the value for the flag 'int_flag'"); } @@ -543,7 +544,7 @@ TEST_F(ParseDeathTest, TestInvalidUDTFlagFormat) { "testbin", "--udt_flag=1", }; - EXPECT_DEATH(InvokeParse(in_args1), + EXPECT_DEATH_IF_SUPPORTED(InvokeParse(in_args1), "Illegal value '1' specified for flag 'udt_flag'; Use values A, " "AAA instead"); @@ -552,7 +553,7 @@ TEST_F(ParseDeathTest, TestInvalidUDTFlagFormat) { "--udt_flag", "AA", }; - EXPECT_DEATH(InvokeParse(in_args2), + EXPECT_DEATH_IF_SUPPORTED(InvokeParse(in_args2), "Illegal value 'AA' specified for flag 'udt_flag'; Use values " "A, AAA instead"); } @@ -658,7 +659,7 @@ TEST_F(ParseDeathTest, TestInvalidFlagfiles) { GetFlagfileFlag({{"parse_test.ff4", absl::MakeConstSpan(ff4_data)}}, &flagfile_flag), }; - EXPECT_DEATH(InvokeParse(in_args1), + EXPECT_DEATH_IF_SUPPORTED(InvokeParse(in_args1), "Unknown command line flag 'unknown_flag'"); constexpr const char* const ff5_data[] = { @@ -670,7 +671,7 @@ TEST_F(ParseDeathTest, TestInvalidFlagfiles) { GetFlagfileFlag({{"parse_test.ff5", absl::MakeConstSpan(ff5_data)}}, &flagfile_flag), }; - EXPECT_DEATH(InvokeParse(in_args2), + EXPECT_DEATH_IF_SUPPORTED(InvokeParse(in_args2), "Unknown command line flag 'int_flag 10'"); constexpr const char* const ff6_data[] = { @@ -682,14 +683,15 @@ TEST_F(ParseDeathTest, TestInvalidFlagfiles) { GetFlagfileFlag({{"parse_test.ff6", absl::MakeConstSpan(ff6_data)}}, &flagfile_flag), }; - EXPECT_DEATH(InvokeParse(in_args3), + EXPECT_DEATH_IF_SUPPORTED(InvokeParse(in_args3), "Flagfile can't contain position arguments or --"); const char* in_args4[] = { "testbin", "--flagfile=invalid_flag_file", }; - EXPECT_DEATH(InvokeParse(in_args4), "Can't open flagfile invalid_flag_file"); + EXPECT_DEATH_IF_SUPPORTED(InvokeParse(in_args4), + "Can't open flagfile invalid_flag_file"); constexpr const char* const ff7_data[] = { "--int_flag=10", @@ -702,7 +704,7 @@ TEST_F(ParseDeathTest, TestInvalidFlagfiles) { GetFlagfileFlag({{"parse_test.ff7", absl::MakeConstSpan(ff7_data)}}, &flagfile_flag), }; - EXPECT_DEATH(InvokeParse(in_args5), + EXPECT_DEATH_IF_SUPPORTED(InvokeParse(in_args5), "Unexpected line in the flagfile .*: \\*bin\\*"); } @@ -724,7 +726,7 @@ TEST_F(ParseTest, TestReadingRequiredFlagsFromEnv) { TEST_F(ParseDeathTest, TestReadingUnsetRequiredFlagsFromEnv) { const char* in_args1[] = {"testbin", "--fromenv=int_flag"}; - EXPECT_DEATH(InvokeParse(in_args1), + EXPECT_DEATH_IF_SUPPORTED(InvokeParse(in_args1), "FLAGS_int_flag not found in environment"); } @@ -735,7 +737,8 @@ TEST_F(ParseDeathTest, TestRecursiveFlagsFromEnv) { ScopedSetEnv set_tryfromenv("FLAGS_tryfromenv", "int_flag"); - EXPECT_DEATH(InvokeParse(in_args1), "Infinite recursion on flag tryfromenv"); + EXPECT_DEATH_IF_SUPPORTED(InvokeParse(in_args1), + "Infinite recursion on flag tryfromenv"); } // -------------------------------------------------------------------- |