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
This commit is contained in:
Abseil Team 2020-04-22 10:52:29 -07:00 committed by Derek Mauro
parent cb52b05ea2
commit 902909a430
11 changed files with 59 additions and 58 deletions

View file

@ -1543,7 +1543,7 @@ TEST(Btree, MapAt) {
#ifdef ABSL_HAVE_EXCEPTIONS
EXPECT_THROW(map.at(3), std::out_of_range);
#else
EXPECT_DEATH(map.at(3), "absl::btree_map::at");
EXPECT_DEATH_IF_SUPPORTED(map.at(3), "absl::btree_map::at");
#endif
}

View file

@ -773,10 +773,10 @@ TEST(FixedArrayTest, AddressSanitizerAnnotations1) {
int* raw = a.data();
raw[0] = 0;
raw[9] = 0;
EXPECT_DEATH(raw[-2] = 0, "container-overflow");
EXPECT_DEATH(raw[-1] = 0, "container-overflow");
EXPECT_DEATH(raw[10] = 0, "container-overflow");
EXPECT_DEATH(raw[31] = 0, "container-overflow");
EXPECT_DEATH_IF_SUPPORTED(raw[-2] = 0, "container-overflow");
EXPECT_DEATH_IF_SUPPORTED(raw[-1] = 0, "container-overflow");
EXPECT_DEATH_IF_SUPPORTED(raw[10] = 0, "container-overflow");
EXPECT_DEATH_IF_SUPPORTED(raw[31] = 0, "container-overflow");
}
TEST(FixedArrayTest, AddressSanitizerAnnotations2) {
@ -784,10 +784,10 @@ TEST(FixedArrayTest, AddressSanitizerAnnotations2) {
char* raw = a.data();
raw[0] = 0;
raw[11] = 0;
EXPECT_DEATH(raw[-7] = 0, "container-overflow");
EXPECT_DEATH(raw[-1] = 0, "container-overflow");
EXPECT_DEATH(raw[12] = 0, "container-overflow");
EXPECT_DEATH(raw[17] = 0, "container-overflow");
EXPECT_DEATH_IF_SUPPORTED(raw[-7] = 0, "container-overflow");
EXPECT_DEATH_IF_SUPPORTED(raw[-1] = 0, "container-overflow");
EXPECT_DEATH_IF_SUPPORTED(raw[12] = 0, "container-overflow");
EXPECT_DEATH_IF_SUPPORTED(raw[17] = 0, "container-overflow");
}
TEST(FixedArrayTest, AddressSanitizerAnnotations3) {
@ -795,8 +795,8 @@ TEST(FixedArrayTest, AddressSanitizerAnnotations3) {
uint64_t* raw = a.data();
raw[0] = 0;
raw[19] = 0;
EXPECT_DEATH(raw[-1] = 0, "container-overflow");
EXPECT_DEATH(raw[20] = 0, "container-overflow");
EXPECT_DEATH_IF_SUPPORTED(raw[-1] = 0, "container-overflow");
EXPECT_DEATH_IF_SUPPORTED(raw[20] = 0, "container-overflow");
}
TEST(FixedArrayTest, AddressSanitizerAnnotations4) {
@ -808,11 +808,11 @@ TEST(FixedArrayTest, AddressSanitizerAnnotations4) {
// there is only a 8-byte red zone before the container range, so we only
// access the last 4 bytes of the struct to make sure it stays within the red
// zone.
EXPECT_DEATH(raw[-1].z_ = 0, "container-overflow");
EXPECT_DEATH(raw[10] = ThreeInts(), "container-overflow");
EXPECT_DEATH_IF_SUPPORTED(raw[-1].z_ = 0, "container-overflow");
EXPECT_DEATH_IF_SUPPORTED(raw[10] = ThreeInts(), "container-overflow");
// The actual size of storage is kDefaultBytes=256, 21*12 = 252,
// so reading raw[21] should still trigger the correct warning.
EXPECT_DEATH(raw[21] = ThreeInts(), "container-overflow");
EXPECT_DEATH_IF_SUPPORTED(raw[21] = ThreeInts(), "container-overflow");
}
#endif // ADDRESS_SANITIZER

View file

@ -55,7 +55,7 @@ TEST_P(FailureSignalHandlerDeathTest, AbslFailureSignal) {
exit_regex);
#else
// Windows doesn't have testing::KilledBySignal().
EXPECT_DEATH(InstallHandlerAndRaise(signo), exit_regex);
EXPECT_DEATH_IF_SUPPORTED(InstallHandlerAndRaise(signo), exit_regex);
#endif
}
@ -107,8 +107,8 @@ TEST_P(FailureSignalHandlerDeathTest, AbslFatalSignalsWithWriterFn) {
testing::KilledBySignal(signo), exit_regex);
#else
// Windows doesn't have testing::KilledBySignal().
EXPECT_DEATH(InstallHandlerWithWriteToFileAndRaise(file.c_str(), signo),
exit_regex);
EXPECT_DEATH_IF_SUPPORTED(
InstallHandlerWithWriteToFileAndRaise(file.c_str(), signo), exit_regex);
#endif
// Open the file in this process and check its contents.

View file

@ -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

View file

@ -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");

View file

@ -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;
}

View file

@ -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
}

View file

@ -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");
}
// --------------------------------------------------------------------

View file

@ -544,7 +544,6 @@ absl_cc_library(
COPTS
${ABSL_DEFAULT_COPTS}
DEPS
absl::strings_internal
absl::base
absl::base_internal
absl::core_headers
@ -555,6 +554,7 @@ absl_cc_library(
absl::optional
absl::raw_logging_internal
absl::strings
absl::strings_internal
absl::type_traits
PUBLIC
)

View file

@ -1051,7 +1051,7 @@ TEST(optionalTest, Value) {
#ifdef ABSL_HAVE_EXCEPTIONS
EXPECT_THROW((void)empty.value(), absl::bad_optional_access);
#else
EXPECT_DEATH((void)empty.value(), "Bad optional access");
EXPECT_DEATH_IF_SUPPORTED((void)empty.value(), "Bad optional access");
#endif
// test constexpr value()

View file

@ -50,7 +50,7 @@
#else
#define ABSL_VARIANT_TEST_EXPECT_FAIL(expr, exception_t, text) \
EXPECT_DEATH(expr, text)
EXPECT_DEATH_IF_SUPPORTED(expr, text)
#endif // ABSL_HAVE_EXCEPTIONS