Replace "#if GTEST_HAS_ABSL" with "#ifdef GTEST_HAS_ABSL"

This allows compilation with "-Wundef" (#3267).

PiperOrigin-RevId: 513945230
Change-Id: I45ef19c7ff3d20e97216bd031d406a03365471da
This commit is contained in:
Tom Hughes 2023-03-03 16:03:22 -08:00 committed by Copybara-Service
parent dc10c3b5e5
commit 16feffa8fa
6 changed files with 22 additions and 21 deletions

View File

@ -857,7 +857,7 @@ class UniversalPrinter<Variant<T...>> {
public:
static void Print(const Variant<T...>& value, ::std::ostream* os) {
*os << '(';
#if GTEST_HAS_ABSL
#ifdef GTEST_HAS_ABSL
absl::visit(Visitor{os, value.index()}, value);
#else
std::visit(Visitor{os, value.index()}, value);

View File

@ -178,6 +178,7 @@
// define themselves.
// GTEST_USES_SIMPLE_RE - our own simple regex is used;
// the above RE\b(s) are mutually exclusive.
// GTEST_HAS_ABSL - Google Test is compiled with Abseil.
// Misc public macros
// ------------------
@ -304,7 +305,7 @@
#include "gtest/internal/custom/gtest-port.h"
#include "gtest/internal/gtest-port-arch.h"
#if GTEST_HAS_ABSL
#ifdef GTEST_HAS_ABSL
#include "absl/flags/declare.h"
#include "absl/flags/flag.h"
#include "absl/flags/reflection.h"
@ -412,7 +413,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
#endif
// Select the regular expression implementation.
#if GTEST_HAS_ABSL
#ifdef GTEST_HAS_ABSL
// When using Abseil, RE2 is required.
#include "absl/strings/string_view.h"
#include "re2/re2.h"
@ -2248,7 +2249,7 @@ using TimeInMillis = int64_t; // Represents time in milliseconds.
#endif // !defined(GTEST_FLAG)
// Pick a command line flags implementation.
#if GTEST_HAS_ABSL
#ifdef GTEST_HAS_ABSL
// Macros for defining flags.
#define GTEST_DEFINE_bool_(name, default_val, doc) \
@ -2359,7 +2360,7 @@ const char* StringFromGTestEnv(const char* flag, const char* default_val);
#endif // !defined(GTEST_INTERNAL_DEPRECATED)
#if GTEST_HAS_ABSL
#ifdef GTEST_HAS_ABSL
// Always use absl::any for UniversalPrinter<> specializations if googletest
// is built with absl support.
#define GTEST_INTERNAL_HAS_ANY 1
@ -2392,7 +2393,7 @@ using Any = ::std::any;
#define GTEST_INTERNAL_HAS_ANY 0
#endif
#if GTEST_HAS_ABSL
#ifdef GTEST_HAS_ABSL
// Always use absl::optional for UniversalPrinter<> specializations if
// googletest is built with absl support.
#define GTEST_INTERNAL_HAS_OPTIONAL 1
@ -2428,7 +2429,7 @@ inline ::std::nullopt_t Nullopt() { return ::std::nullopt; }
#define GTEST_INTERNAL_HAS_OPTIONAL 0
#endif
#if GTEST_HAS_ABSL
#ifdef GTEST_HAS_ABSL
// Always use absl::string_view for Matcher<> specializations if googletest
// is built with absl support.
#define GTEST_INTERNAL_HAS_STRING_VIEW 1
@ -2460,7 +2461,7 @@ using StringView = ::std::string_view;
#define GTEST_INTERNAL_HAS_STRING_VIEW 0
#endif
#if GTEST_HAS_ABSL
#ifdef GTEST_HAS_ABSL
// Always use absl::variant for UniversalPrinter<> specializations if googletest
// is built with absl support.
#define GTEST_INTERNAL_HAS_VARIANT 1

View File

@ -442,7 +442,7 @@ class OsStackTraceGetter : public OsStackTraceGetterInterface {
void UponLeavingGTest() override;
private:
#if GTEST_HAS_ABSL
#ifdef GTEST_HAS_ABSL
Mutex mutex_; // Protects all internal state.
// We save the stack frame below the frame that calls user code.

View File

@ -135,7 +135,7 @@
#endif
#endif
#if GTEST_HAS_ABSL
#ifdef GTEST_HAS_ABSL
#include "absl/debugging/failure_signal_handler.h"
#include "absl/debugging/stacktrace.h"
#include "absl/debugging/symbolize.h"
@ -4958,7 +4958,7 @@ const char* const OsStackTraceGetterInterface::kElidedFramesMarker =
std::string OsStackTraceGetter::CurrentStackTrace(int max_depth, int skip_count)
GTEST_LOCK_EXCLUDED_(mutex_) {
#if GTEST_HAS_ABSL
#ifdef GTEST_HAS_ABSL
std::string result;
if (max_depth <= 0) {
@ -5007,7 +5007,7 @@ std::string OsStackTraceGetter::CurrentStackTrace(int max_depth, int skip_count)
}
void OsStackTraceGetter::UponLeavingGTest() GTEST_LOCK_EXCLUDED_(mutex_) {
#if GTEST_HAS_ABSL
#ifdef GTEST_HAS_ABSL
void* caller_frame = nullptr;
if (absl::GetStackTrace(&caller_frame, 1, 3) <= 0) {
caller_frame = nullptr;
@ -5686,7 +5686,7 @@ void UnitTestImpl::PostFlagParsingInit() {
ConfigureStreamingOutput();
#endif // GTEST_CAN_STREAM_RESULTS_
#if GTEST_HAS_ABSL
#ifdef GTEST_HAS_ABSL
if (GTEST_FLAG_GET(install_failure_signal_handler)) {
absl::FailureSignalHandlerOptions options;
absl::InstallFailureSignalHandler(options);
@ -6668,7 +6668,7 @@ void ParseGoogleTestFlagsOnlyImpl(int* argc, CharType** argv) {
// Parses the command line for Google Test flags, without initializing
// other parts of Google Test.
void ParseGoogleTestFlagsOnly(int* argc, char** argv) {
#if GTEST_HAS_ABSL
#ifdef GTEST_HAS_ABSL
if (*argc > 0) {
// absl::ParseCommandLine() requires *argc > 0.
auto positional_args = absl::flags_internal::ParseCommandLineImpl(
@ -6720,7 +6720,7 @@ void InitGoogleTestImpl(int* argc, CharType** argv) {
g_argvs.push_back(StreamableToString(argv[i]));
}
#if GTEST_HAS_ABSL
#ifdef GTEST_HAS_ABSL
absl::InitializeSymbolizer(g_argvs[0].c_str());
// When using the Abseil Flags library, set the program usage message to the

View File

@ -390,7 +390,7 @@ TEST(GtestCheckDeathTest, LivesSilentlyOnSuccess) {
// the platform. The test will produce compiler errors in case of failure.
// For simplicity, we only cover the most important platforms here.
TEST(RegexEngineSelectionTest, SelectsCorrectRegexEngine) {
#if GTEST_HAS_ABSL
#ifdef GTEST_HAS_ABSL
EXPECT_TRUE(GTEST_USES_RE2);
#elif GTEST_HAS_POSIX_RE
EXPECT_TRUE(GTEST_USES_POSIX_RE);

View File

@ -6178,12 +6178,12 @@ TEST_F(ParseFlagsTest, FilterBad) {
const char* argv2[] = {"foo.exe", "--gtest_filter", nullptr};
#if GTEST_HAS_ABSL && defined(GTEST_HAS_DEATH_TEST)
#if defined(GTEST_HAS_ABSL) && defined(GTEST_HAS_DEATH_TEST)
// Invalid flag arguments are a fatal error when using the Abseil Flags.
EXPECT_EXIT(GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Filter(""), true),
testing::ExitedWithCode(1),
"ERROR: Missing the value for the flag 'gtest_filter'");
#elif !GTEST_HAS_ABSL
#elif !defined(GTEST_HAS_ABSL)
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags::Filter(""), true);
#else
static_cast<void>(argv);
@ -6197,12 +6197,12 @@ TEST_F(ParseFlagsTest, OutputEmpty) {
const char* argv2[] = {"foo.exe", "--gtest_output", nullptr};
#if GTEST_HAS_ABSL && defined(GTEST_HAS_DEATH_TEST)
#if defined(GTEST_HAS_ABSL) && defined(GTEST_HAS_DEATH_TEST)
// Invalid flag arguments are a fatal error when using the Abseil Flags.
EXPECT_EXIT(GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags(), true),
testing::ExitedWithCode(1),
"ERROR: Missing the value for the flag 'gtest_output'");
#elif !GTEST_HAS_ABSL
#elif !defined(GTEST_HAS_ABSL)
GTEST_TEST_PARSING_FLAGS_(argv, argv2, Flags(), true);
#else
static_cast<void>(argv);
@ -6210,7 +6210,7 @@ TEST_F(ParseFlagsTest, OutputEmpty) {
#endif
}
#if GTEST_HAS_ABSL
#ifdef GTEST_HAS_ABSL
TEST_F(ParseFlagsTest, AbseilPositionalFlags) {
const char* argv[] = {"foo.exe", "--gtest_throw_on_failure=1", "--",
"--other_flag", nullptr};