Skip to content

Commit

Permalink
If GTEST_NO_ABSL_FLAGS is #defined, then the Abseil flag library
Browse files Browse the repository at this point in the history
will not be used by googletest, even if GTEST_HAS_ABSL is #defined.

PiperOrigin-RevId: 599625032
Change-Id: Ieb994a15683dec89e88578120071eca8ac9fead1
  • Loading branch information
Abseil Team authored and copybara-github committed Jan 18, 2024
1 parent f6f920d commit 96cd50c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 7 additions & 5 deletions googletest/include/gtest/internal/gtest-port.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,10 @@
#define GTEST_HAS_NOTIFICATION_ 0
#endif

#ifdef GTEST_HAS_ABSL
#include "absl/flags/declare.h"
#if defined(GTEST_HAS_ABSL) && !defined(GTEST_NO_ABSL_FLAGS)
#define GTEST_INTERNAL_HAS_ABSL_FLAGS // Used only in this file.
#include "absl/flags/flag.h"
#include "absl/flags/declare.h"
#include "absl/flags/reflection.h"
#endif

Expand Down Expand Up @@ -2252,7 +2253,7 @@ using TimeInMillis = int64_t; // Represents time in milliseconds.
#endif // !defined(GTEST_FLAG)

// Pick a command line flags implementation.
#ifdef GTEST_HAS_ABSL
#ifdef GTEST_INTERNAL_HAS_ABSL_FLAGS

// Macros for defining flags.
#define GTEST_DEFINE_bool_(name, default_val, doc) \
Expand All @@ -2277,7 +2278,8 @@ using TimeInMillis = int64_t; // Represents time in milliseconds.
(void)(::absl::SetFlag(&GTEST_FLAG(name), value))
#define GTEST_USE_OWN_FLAGFILE_FLAG_ 0

#else // GTEST_HAS_ABSL
#undef GTEST_INTERNAL_HAS_ABSL_FLAGS
#else // ndef GTEST_INTERNAL_HAS_ABSL_FLAGS

// Macros for defining flags.
#define GTEST_DEFINE_bool_(name, default_val, doc) \
Expand Down Expand Up @@ -2319,7 +2321,7 @@ using TimeInMillis = int64_t; // Represents time in milliseconds.
#define GTEST_FLAG_SET(name, value) (void)(::testing::GTEST_FLAG(name) = value)
#define GTEST_USE_OWN_FLAGFILE_FLAG_ 1

#endif // GTEST_HAS_ABSL
#endif // GTEST_INTERNAL_HAS_ABSL_FLAGS

// Thread annotations
#if !defined(GTEST_EXCLUSIVE_LOCK_REQUIRED_)
Expand Down
8 changes: 7 additions & 1 deletion googletest/src/gtest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@
#define GTEST_HAS_BUILTIN(x) 0
#endif // defined(__has_builtin)

#if defined(GTEST_HAS_ABSL) && !defined(GTEST_NO_ABSL_FLAGS)
#define GTEST_HAS_ABSL_FLAGS
#endif

namespace testing {

using internal::CountIf;
Expand Down Expand Up @@ -6688,7 +6692,7 @@ void ParseGoogleTestFlagsOnlyImpl(int* argc, CharType** argv) {
// remain in place. Unrecognized flags are not reported and do not cause the
// program to exit.
void ParseGoogleTestFlagsOnly(int* argc, char** argv) {
#ifdef GTEST_HAS_ABSL
#ifdef GTEST_HAS_ABSL_FLAGS
if (*argc <= 0) return;

std::vector<char*> positional_args;
Expand Down Expand Up @@ -6774,11 +6778,13 @@ void InitGoogleTestImpl(int* argc, CharType** argv) {
#ifdef GTEST_HAS_ABSL
absl::InitializeSymbolizer(g_argvs[0].c_str());

#ifdef GTEST_HAS_ABSL_FLAGS
// When using the Abseil Flags library, set the program usage message to the
// help message, but remove the color-encoding from the message first.
absl::SetProgramUsageMessage(absl::StrReplaceAll(
kColorEncodedHelpMessage,
{{"@D", ""}, {"@R", ""}, {"@G", ""}, {"@Y", ""}, {"@@", "@"}}));
#endif // GTEST_HAS_ABSL_FLAGS
#endif // GTEST_HAS_ABSL

ParseGoogleTestFlagsOnly(argc, argv);
Expand Down

0 comments on commit 96cd50c

Please sign in to comment.