Use "#ifdef" with public macros

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

PiperOrigin-RevId: 513944726
Change-Id: I1a3854bb2333d5dec6c0ff91ee1eddd9a766ab91
This commit is contained in:
Tom Hughes 2023-03-03 16:01:13 -08:00 committed by Copybara-Service
parent 7b1ced0682
commit dc10c3b5e5
17 changed files with 50 additions and 50 deletions

View File

@ -200,7 +200,7 @@ TEST(IsTrueTest, IsTrueIsFalse) {
EXPECT_THAT(nonnull_unique, Not(IsFalse()));
}
#if GTEST_HAS_TYPED_TEST
#ifdef GTEST_HAS_TYPED_TEST
// Tests ContainerEq with different container types, and
// different element types.

View File

@ -1088,7 +1088,7 @@ TEST(UnexpectedCallTest, UnsatisfiedPrerequisites) {
// Verifies that the failure message contains the two unsatisfied
// pre-requisites but not the satisfied one.
#if GTEST_USES_POSIX_RE
#ifdef GTEST_USES_POSIX_RE
EXPECT_THAT(r.message(),
ContainsRegex(
// POSIX RE doesn't understand the (?s) prefix, but has no

View File

@ -51,7 +51,7 @@ GTEST_DECLARE_string_(death_test_style);
namespace testing {
#if GTEST_HAS_DEATH_TEST
#ifdef GTEST_HAS_DEATH_TEST
namespace internal {
@ -328,7 +328,7 @@ class GTEST_API_ KilledBySignal {
// death tests are supported; otherwise they just issue a warning. This is
// useful when you are combining death test assertions with normal test
// assertions in one test.
#if GTEST_HAS_DEATH_TEST
#ifdef GTEST_HAS_DEATH_TEST
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \
EXPECT_DEATH(statement, regex)
#define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \

View File

@ -600,7 +600,7 @@ class GTEST_API_ TestInfo {
const TestResult* result() const { return &result_; }
private:
#if GTEST_HAS_DEATH_TEST
#ifdef GTEST_HAS_DEATH_TEST
friend class internal::DefaultDeathTestFactory;
#endif // GTEST_HAS_DEATH_TEST
friend class Test;

View File

@ -57,7 +57,7 @@ const char kDeathTestStyleFlag[] = "death_test_style";
const char kDeathTestUseFork[] = "death_test_use_fork";
const char kInternalRunDeathTestFlag[] = "internal_run_death_test";
#if GTEST_HAS_DEATH_TEST
#ifdef GTEST_HAS_DEATH_TEST
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
/* class A needs to have dll-interface to be used by clients of class B */)

View File

@ -161,10 +161,10 @@
// NOT define them.
//
// These macros are public so that portable tests can be written.
// Such tests typically surround code using a feature with an #if
// Such tests typically surround code using a feature with an #ifdef
// which controls that code. For example:
//
// #if GTEST_HAS_DEATH_TEST
// #ifdef GTEST_HAS_DEATH_TEST
// EXPECT_DEATH(DoSomethingDeadly());
// #endif
//
@ -794,7 +794,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
#endif // GTEST_IS_THREADSAFE
#if GTEST_IS_THREADSAFE
#ifdef GTEST_IS_THREADSAFE
// Some platforms don't support including these threading related headers.
#include <condition_variable> // NOLINT
#include <mutex> // NOLINT
@ -909,7 +909,7 @@ GTEST_API_ bool IsTrue(bool condition);
// Defines RE.
#if GTEST_USES_RE2
#ifdef GTEST_USES_RE2
// This is almost `using RE = ::RE2`, except it is copy-constructible, and it
// needs to disambiguate the `std::string`, `absl::string_view`, and `const
@ -934,7 +934,7 @@ class GTEST_API_ RE {
RE2 regex_;
};
#elif GTEST_USES_POSIX_RE || GTEST_USES_SIMPLE_RE
#elif defined(GTEST_USES_POSIX_RE) || defined(GTEST_USES_SIMPLE_RE)
// A simple C++ wrapper for <regex.h>. It uses the POSIX Extended
// Regular Expression syntax.
@ -972,7 +972,7 @@ class GTEST_API_ RE {
std::string pattern_;
bool is_valid_;
#if GTEST_USES_POSIX_RE
#ifdef GTEST_USES_POSIX_RE
regex_t full_regex_; // For FullMatch().
regex_t partial_regex_; // For PartialMatch().
@ -1200,7 +1200,7 @@ GTEST_API_ std::string ReadEntireFile(FILE* file);
// All command line arguments.
GTEST_API_ std::vector<std::string> GetArgvs();
#if GTEST_HAS_DEATH_TEST
#ifdef GTEST_HAS_DEATH_TEST
std::vector<std::string> GetInjectableArgvs();
// Deprecated: pass the args vector by value instead.
@ -1211,7 +1211,7 @@ void ClearInjectableArgvs();
#endif // GTEST_HAS_DEATH_TEST
// Defines synchronization primitives.
#if GTEST_IS_THREADSAFE
#ifdef GTEST_IS_THREADSAFE
#ifdef GTEST_OS_WINDOWS
// Provides leak-safe Windows kernel handle ownership.

View File

@ -40,7 +40,7 @@
#include "gtest/internal/custom/gtest.h"
#include "gtest/internal/gtest-port.h"
#if GTEST_HAS_DEATH_TEST
#ifdef GTEST_HAS_DEATH_TEST
#ifdef GTEST_OS_MAC
#include <crt_externs.h>
@ -133,7 +133,7 @@ GTEST_DEFINE_string_(
namespace testing {
#if GTEST_HAS_DEATH_TEST
#ifdef GTEST_HAS_DEATH_TEST
namespace internal {

View File

@ -672,7 +672,7 @@ class GTEST_API_ UnitTestImpl {
void AddTestInfo(internal::SetUpTestSuiteFunc set_up_tc,
internal::TearDownTestSuiteFunc tear_down_tc,
TestInfo* test_info) {
#if GTEST_HAS_DEATH_TEST
#ifdef GTEST_HAS_DEATH_TEST
// In order to support thread-safe death tests, we need to
// remember the original working directory when the test program
// was first invoked. We cannot do this in RUN_ALL_TESTS(), as
@ -778,7 +778,7 @@ class GTEST_API_ UnitTestImpl {
return gtest_trace_stack_.get();
}
#if GTEST_HAS_DEATH_TEST
#ifdef GTEST_HAS_DEATH_TEST
void InitDeathTestSubprocessControlInfo() {
internal_run_death_test_flag_.reset(ParseInternalRunDeathTestFlag());
}
@ -943,7 +943,7 @@ class GTEST_API_ UnitTestImpl {
// How long the test took to run, in milliseconds.
TimeInMillis elapsed_time_;
#if GTEST_HAS_DEATH_TEST
#ifdef GTEST_HAS_DEATH_TEST
// The decomposed components of the gtest_internal_run_death_test flag,
// parsed when RUN_ALL_TESTS is called.
std::unique_ptr<InternalRunDeathTestFlag> internal_run_death_test_flag_;
@ -967,7 +967,7 @@ inline UnitTestImpl* GetUnitTestImpl() {
return UnitTest::GetInstance()->impl();
}
#if GTEST_USES_SIMPLE_RE
#ifdef GTEST_USES_SIMPLE_RE
// Internal helper functions for implementing the simple regular
// expression matcher.
@ -993,7 +993,7 @@ GTEST_API_ bool MatchRegexAnywhere(const char* regex, const char* str);
GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, char** argv);
GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, wchar_t** argv);
#if GTEST_HAS_DEATH_TEST
#ifdef GTEST_HAS_DEATH_TEST
// Returns the message describing the last system error, regardless of the
// platform.

View File

@ -657,7 +657,7 @@ void ThreadLocalRegistry::OnThreadLocalDestroyed(
#endif // GTEST_IS_THREADSAFE && GTEST_OS_WINDOWS
#if GTEST_USES_POSIX_RE
#ifdef GTEST_USES_POSIX_RE
// Implements RE. Currently only needed for death tests.
@ -719,7 +719,7 @@ void RE::Init(const char* regex) {
delete[] full_pattern;
}
#elif GTEST_USES_SIMPLE_RE
#elif defined(GTEST_USES_SIMPLE_RE)
// Returns true if and only if ch appears anywhere in str (excluding the
// terminating '\0' character).
@ -1221,7 +1221,7 @@ std::string ReadEntireFile(FILE* file) {
return content;
}
#if GTEST_HAS_DEATH_TEST
#ifdef GTEST_HAS_DEATH_TEST
static const std::vector<std::string>* g_injected_test_argvs =
nullptr; // Owned.

View File

@ -5018,7 +5018,7 @@ void OsStackTraceGetter::UponLeavingGTest() GTEST_LOCK_EXCLUDED_(mutex_) {
#endif // GTEST_HAS_ABSL
}
#if GTEST_HAS_DEATH_TEST
#ifdef GTEST_HAS_DEATH_TEST
// A helper class that creates the premature-exit file in its
// constructor and deletes the file in its destructor.
class ScopedPrematureExitFile {
@ -5383,7 +5383,7 @@ void UnitTest::RecordProperty(const std::string& key,
// We don't protect this under mutex_, as we only support calling it
// from the main thread.
int UnitTest::Run() {
#if GTEST_HAS_DEATH_TEST
#ifdef GTEST_HAS_DEATH_TEST
const bool in_death_test_child_process =
GTEST_FLAG_GET(internal_run_death_test).length() > 0;
@ -5560,7 +5560,7 @@ UnitTestImpl::UnitTestImpl(UnitTest* parent)
random_(0), // Will be reseeded before first use.
start_timestamp_(0),
elapsed_time_(0),
#if GTEST_HAS_DEATH_TEST
#ifdef GTEST_HAS_DEATH_TEST
death_test_factory_(new DefaultDeathTestFactory),
#endif
// Will be overridden by the flag before first use.
@ -5600,7 +5600,7 @@ void UnitTestImpl::RecordProperty(const TestProperty& test_property) {
test_result->RecordProperty(xml_element, test_property);
}
#if GTEST_HAS_DEATH_TEST
#ifdef GTEST_HAS_DEATH_TEST
// Disables event forwarding if the control is currently in a death test
// subprocess. Must not be called before InitGoogleTest.
void UnitTestImpl::SuppressTestEventsIfInSubprocess() {
@ -5663,7 +5663,7 @@ void UnitTestImpl::PostFlagParsingInit() {
listeners()->Append(new GTEST_CUSTOM_TEST_EVENT_LISTENER_());
#endif // defined(GTEST_CUSTOM_TEST_EVENT_LISTENER_)
#if GTEST_HAS_DEATH_TEST
#ifdef GTEST_HAS_DEATH_TEST
InitDeathTestSubprocessControlInfo();
SuppressTestEventsIfInSubprocess();
#endif // GTEST_HAS_DEATH_TEST
@ -5801,7 +5801,7 @@ bool UnitTestImpl::RunAllTests() {
// death test.
bool in_subprocess_for_death_test = false;
#if GTEST_HAS_DEATH_TEST
#ifdef GTEST_HAS_DEATH_TEST
in_subprocess_for_death_test =
(internal_run_death_test_flag_.get() != nullptr);
#if defined(GTEST_EXTRA_DEATH_TEST_CHILD_SETUP_)

View File

@ -37,7 +37,7 @@
using testing::internal::AlwaysFalse;
using testing::internal::AlwaysTrue;
#if GTEST_HAS_DEATH_TEST
#ifdef GTEST_HAS_DEATH_TEST
#ifdef GTEST_OS_WINDOWS
#include <direct.h> // For chdir().
@ -1353,7 +1353,7 @@ void DieWithMessage(const char* message) {
TEST(MatcherDeathTest, DoesNotBreakBareRegexMatching) {
// googletest tests this, of course; here we ensure that including googlemock
// has not broken it.
#if GTEST_USES_POSIX_RE
#ifdef GTEST_USES_POSIX_RE
EXPECT_DEATH(DieWithMessage("O, I die, Horatio."), "I d[aeiou]e");
#else
EXPECT_DEATH(DieWithMessage("O, I die, Horatio."), "I di?e");

View File

@ -33,7 +33,7 @@
#include "gtest/gtest-death-test.h"
#include "gtest/gtest.h"
#if GTEST_HAS_DEATH_TEST
#ifdef GTEST_HAS_DEATH_TEST
#if GTEST_HAS_SEH
#include <windows.h> // For RaiseException().

View File

@ -41,7 +41,7 @@
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4127 /* conditional expression is constant */)
#if GTEST_IS_THREADSAFE
#ifdef GTEST_IS_THREADSAFE
using testing::ScopedFakeTestPartResultReporter;
using testing::TestPartResultArray;
@ -247,7 +247,7 @@ TEST(SCOPED_TRACETest, CanBeRepeated) {
<< "contain trace point A, B, and D.";
}
#if GTEST_IS_THREADSAFE
#ifdef GTEST_IS_THREADSAFE
// Tests that SCOPED_TRACE()s can be used concurrently from multiple
// threads. Namely, an assertion should be affected by
// SCOPED_TRACE()s in its own thread only.
@ -773,7 +773,7 @@ REGISTER_TYPED_TEST_SUITE_P(DetectNotInstantiatedTypesTest, Used);
// typedef ::testing::Types<char, int, unsigned int> MyTypes;
// INSTANTIATE_TYPED_TEST_SUITE_P(All, DetectNotInstantiatedTypesTest, MyTypes);
#if GTEST_HAS_DEATH_TEST
#ifdef GTEST_HAS_DEATH_TEST
// We rely on the golden file to verify that tests whose test case
// name ends with DeathTest are run first.
@ -851,7 +851,7 @@ TEST_F(ExpectFailureTest, ExpectNonFatalFailure) {
"failure.");
}
#if GTEST_IS_THREADSAFE
#ifdef GTEST_IS_THREADSAFE
class ExpectFailureWithThreadsTest : public ExpectFailureTest {
protected:
@ -1024,7 +1024,7 @@ int main(int argc, char** argv) {
std::count(argv, argv + argc,
std::string("internal_skip_environment_and_ad_hoc_tests")) > 0;
#if GTEST_HAS_DEATH_TEST
#ifdef GTEST_HAS_DEATH_TEST
if (GTEST_FLAG_GET(internal_run_death_test) != "") {
// Skip the usual output capturing if we're running as the child
// process of an threadsafe-style death test.

View File

@ -361,7 +361,7 @@ TEST(GtestCheckDeathTest, DiesWithCorrectOutputOnFailure) {
const char regex[] =
#ifdef _MSC_VER
"googletest-port-test\\.cc\\(\\d+\\):"
#elif GTEST_USES_POSIX_RE
#elif defined(GTEST_USES_POSIX_RE)
"googletest-port-test\\.cc:[0-9]+"
#else
"googletest-port-test\\.cc:\\d+"
@ -372,7 +372,7 @@ TEST(GtestCheckDeathTest, DiesWithCorrectOutputOnFailure) {
regex);
}
#if GTEST_HAS_DEATH_TEST
#ifdef GTEST_HAS_DEATH_TEST
TEST(GtestCheckDeathTest, LivesSilentlyOnSuccess) {
EXPECT_EXIT(
@ -399,7 +399,7 @@ TEST(RegexEngineSelectionTest, SelectsCorrectRegexEngine) {
#endif
}
#if GTEST_USES_POSIX_RE
#ifdef GTEST_USES_POSIX_RE
template <typename Str>
class RETest : public ::testing::Test {};
@ -456,7 +456,7 @@ TYPED_TEST(RETest, PartialMatchWorks) {
EXPECT_FALSE(RE::PartialMatch(TypeParam("zza"), re));
}
#elif GTEST_USES_SIMPLE_RE
#elif defined(GTEST_USES_SIMPLE_RE)
TEST(IsInSetTest, NulCharIsNotInAnySet) {
EXPECT_FALSE(IsInSet('\0', ""));
@ -1011,7 +1011,7 @@ TEST(ThreadLocalTest, PointerAndConstPointerReturnSameValue) {
EXPECT_EQ(thread_local_string.pointer(), const_thread_local_string.pointer());
}
#if GTEST_IS_THREADSAFE
#ifdef GTEST_IS_THREADSAFE
void AddTwo(int* param) { *param += 2; }

View File

@ -39,6 +39,6 @@ TEST(HelpFlagTest, ShouldNotBeRun) {
ASSERT_TRUE(false) << "Tests shouldn't be run when --help is specified.";
}
#if GTEST_HAS_DEATH_TEST
#ifdef GTEST_HAS_DEATH_TEST
TEST(DeathTest, UsedByPythonScriptToDetectSupportForDeathTestsInThisBinary) {}
#endif

View File

@ -35,7 +35,7 @@
#include "gtest/gtest.h"
#include "src/gtest-internal-inl.h"
#if GTEST_IS_THREADSAFE
#ifdef GTEST_IS_THREADSAFE
namespace testing {
namespace {

View File

@ -270,7 +270,7 @@ using testing::internal::CaptureStdout;
using testing::internal::GetCapturedStdout;
#endif
#if GTEST_IS_THREADSAFE
#ifdef GTEST_IS_THREADSAFE
using testing::internal::ThreadWithParam;
#endif
@ -1189,7 +1189,7 @@ TEST_F(ScopedFakeTestPartResultReporterTest, DeprecatedConstructor) {
EXPECT_EQ(1, results.size());
}
#if GTEST_IS_THREADSAFE
#ifdef GTEST_IS_THREADSAFE
class ScopedFakeTestPartResultReporterWithThreadsTest
: public ScopedFakeTestPartResultReporterTest {
@ -1347,7 +1347,7 @@ TEST_F(ExpectNonfatalFailureTest, AcceptsMacroThatExpandsToUnprotectedComma) {
"");
}
#if GTEST_IS_THREADSAFE
#ifdef GTEST_IS_THREADSAFE
typedef ScopedFakeTestPartResultReporterWithThreadsTest
ExpectFailureWithThreadsTest;
@ -6178,7 +6178,7 @@ TEST_F(ParseFlagsTest, FilterBad) {
const char* argv2[] = {"foo.exe", "--gtest_filter", nullptr};
#if GTEST_HAS_ABSL && GTEST_HAS_DEATH_TEST
#if 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),
@ -6197,7 +6197,7 @@ TEST_F(ParseFlagsTest, OutputEmpty) {
const char* argv2[] = {"foo.exe", "--gtest_output", nullptr};
#if GTEST_HAS_ABSL && GTEST_HAS_DEATH_TEST
#if 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),