diff options
Diffstat (limited to 'absl/flags/flag_test.cc')
-rw-r--r-- | absl/flags/flag_test.cc | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/absl/flags/flag_test.cc b/absl/flags/flag_test.cc index 53ad4635..8bc7cdfd 100644 --- a/absl/flags/flag_test.cc +++ b/absl/flags/flag_test.cc @@ -19,14 +19,13 @@ #include <stdint.h> #include <atomic> -#include <cmath> -#include <new> #include <string> #include <thread> // NOLINT #include <vector> #include "gtest/gtest.h" #include "absl/base/attributes.h" +#include "absl/base/internal/raw_logging.h" #include "absl/base/macros.h" #include "absl/flags/config.h" #include "absl/flags/declare.h" @@ -40,7 +39,9 @@ #include "absl/strings/str_cat.h" #include "absl/strings/str_split.h" #include "absl/strings/string_view.h" +#include "absl/time/clock.h" #include "absl/time/time.h" +#include "absl/types/optional.h" ABSL_DECLARE_FLAG(int64_t, mistyped_int_flag); ABSL_DECLARE_FLAG(std::vector<std::string>, mistyped_string_flag); @@ -226,9 +227,10 @@ ABSL_DECLARE_FLAG(absl::uint128, test_flag_14); namespace { -#if !ABSL_FLAGS_STRIP_NAMES - TEST_F(FlagTest, TestFlagDeclaration) { +#if ABSL_FLAGS_STRIP_NAMES + GTEST_SKIP() << "This test requires flag names to be present"; +#endif // test that we can access flag objects. EXPECT_EQ(absl::GetFlagReflectionHandle(FLAGS_test_flag_01).Name(), "test_flag_01"); @@ -259,12 +261,27 @@ TEST_F(FlagTest, TestFlagDeclaration) { EXPECT_EQ(absl::GetFlagReflectionHandle(FLAGS_test_flag_14).Name(), "test_flag_14"); } -#endif // !ABSL_FLAGS_STRIP_NAMES - -// -------------------------------------------------------------------- } // namespace +#if ABSL_FLAGS_STRIP_NAMES +// The intent of this helper struct and an expression below is to make sure that +// in the configuration where ABSL_FLAGS_STRIP_NAMES=1 registrar construction +// (in cases of of no Tail calls like OnUpdate) is constexpr and thus can and +// should be completely optimized away, thus avoiding the cost/overhead of +// static initializers. +struct VerifyConsteval { + friend consteval flags::FlagRegistrarEmpty operator+( + flags::FlagRegistrarEmpty, VerifyConsteval) { + return {}; + } +}; + +ABSL_FLAG(int, test_registrar_const_init, 0, "") + VerifyConsteval(); +#endif + +// -------------------------------------------------------------------- + ABSL_FLAG(bool, test_flag_01, true, "test flag 01"); ABSL_FLAG(int, test_flag_02, 1234, "test flag 02"); ABSL_FLAG(int16_t, test_flag_03, -34, "test flag 03"); @@ -283,8 +300,10 @@ ABSL_FLAG(absl::uint128, test_flag_14, absl::MakeUint128(0, 0xFFFAAABBBCCCDDD), namespace { -#if !ABSL_FLAGS_STRIP_NAMES TEST_F(FlagTest, TestFlagDefinition) { +#if ABSL_FLAGS_STRIP_NAMES + GTEST_SKIP() << "This test requires flag names to be present"; +#endif absl::string_view expected_file_name = "absl/flags/flag_test.cc"; EXPECT_EQ(absl::GetFlagReflectionHandle(FLAGS_test_flag_01).Name(), @@ -413,7 +432,6 @@ TEST_F(FlagTest, TestFlagDefinition) { expected_file_name)) << absl::GetFlagReflectionHandle(FLAGS_test_flag_14).Filename(); } -#endif // !ABSL_FLAGS_STRIP_NAMES // -------------------------------------------------------------------- @@ -604,6 +622,9 @@ TEST_F(FlagTest, TestGetSet) { // -------------------------------------------------------------------- TEST_F(FlagTest, TestGetViaReflection) { +#if ABSL_FLAGS_STRIP_NAMES + GTEST_SKIP() << "This test requires flag names to be present"; +#endif auto* handle = absl::FindCommandLineFlag("test_flag_01"); EXPECT_EQ(*handle->TryGet<bool>(), true); handle = absl::FindCommandLineFlag("test_flag_02"); @@ -638,6 +659,9 @@ TEST_F(FlagTest, TestGetViaReflection) { // -------------------------------------------------------------------- TEST_F(FlagTest, ConcurrentSetAndGet) { +#if ABSL_FLAGS_STRIP_NAMES + GTEST_SKIP() << "This test requires flag names to be present"; +#endif static constexpr int kNumThreads = 8; // Two arbitrary durations. One thread will concurrently flip the flag // between these two values, while the other threads read it and verify @@ -785,10 +809,12 @@ TEST_F(FlagTest, TestCustomUDT) { // MSVC produces link error on the type mismatch. // Linux does not have build errors and validations work as expected. #if !defined(_WIN32) && GTEST_HAS_DEATH_TEST - using FlagDeathTest = FlagTest; TEST_F(FlagDeathTest, TestTypeMismatchValidations) { +#if ABSL_FLAGS_STRIP_NAMES + GTEST_SKIP() << "This test requires flag names to be present"; +#endif #if !defined(NDEBUG) EXPECT_DEATH_IF_SUPPORTED( static_cast<void>(absl::GetFlag(FLAGS_mistyped_int_flag)), |