From f3dbe3ec44e0163c4659ec7cd541ca7af66632bc Mon Sep 17 00:00:00 2001 From: dmauro Date: Wed, 14 Oct 2020 14:50:53 -0400 Subject: [PATCH] Googletest export Disable warnings on code that intentionally tests a suboptimal syntax PiperOrigin-RevId: 337138442 --- googletest/test/googletest-death-test-test.cc | 20 +++++++++++ googletest/test/googletest-port-test.cc | 10 ++++++ googletest/test/gtest_unittest.cc | 34 ++++++++++++++++--- 3 files changed, 60 insertions(+), 4 deletions(-) diff --git a/googletest/test/googletest-death-test-test.cc b/googletest/test/googletest-death-test-test.cc index 1bb5bb71..c0b3d1f2 100644 --- a/googletest/test/googletest-death-test-test.cc +++ b/googletest/test/googletest-death-test-test.cc @@ -298,6 +298,13 @@ TEST(ExitStatusPredicateTest, KilledBySignal) { # endif // GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA +// The following code intentionally tests a suboptimal syntax. +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdangling-else" +#pragma GCC diagnostic ignored "-Wempty-body" +#pragma GCC diagnostic ignored "-Wpragmas" +#endif // Tests that the death test macros expand to code which may or may not // be followed by operator<<, and that in either case the complete text // comprises only a single C++ statement. @@ -321,6 +328,9 @@ TEST_F(TestForDeathTest, SingleStatement) { else EXPECT_DEATH(_exit(1), "") << 1 << 2 << 3; } +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif # if GTEST_USES_PCRE @@ -1468,6 +1478,13 @@ TEST(ConditionalDeathMacrosTest, AssertDeatDoesNotReturnhIfUnsupported) { namespace { +// The following code intentionally tests a suboptimal syntax. +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdangling-else" +#pragma GCC diagnostic ignored "-Wempty-body" +#pragma GCC diagnostic ignored "-Wpragmas" +#endif // Tests that the death test macros expand to code which may or may not // be followed by operator<<, and that in either case the complete text // comprises only a single C++ statement. @@ -1493,6 +1510,9 @@ TEST(ConditionalDeathMacrosSyntaxDeathTest, SingleStatement) { else EXPECT_DEATH_IF_SUPPORTED(_exit(1), "") << 1 << 2 << 3; } +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif // Tests that conditional death test macros expand to code which interacts // well with switch statements. diff --git a/googletest/test/googletest-port-test.cc b/googletest/test/googletest-port-test.cc index 44b99ce5..4a87df0b 100644 --- a/googletest/test/googletest-port-test.cc +++ b/googletest/test/googletest-port-test.cc @@ -201,6 +201,13 @@ TEST(ImplicitCastTest, CanUseImplicitConstructor) { EXPECT_TRUE(converted); } +// The following code intentionally tests a suboptimal syntax. +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdangling-else" +#pragma GCC diagnostic ignored "-Wempty-body" +#pragma GCC diagnostic ignored "-Wpragmas" +#endif TEST(GtestCheckSyntaxTest, BehavesLikeASingleStatement) { if (AlwaysFalse()) GTEST_CHECK_(false) << "This should never be executed; " @@ -216,6 +223,9 @@ TEST(GtestCheckSyntaxTest, BehavesLikeASingleStatement) { else GTEST_CHECK_(true) << ""; } +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif TEST(GtestCheckSyntaxTest, WorksWithSwitch) { switch (0) { diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index aa4c21a6..140395fb 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -4131,11 +4131,13 @@ TEST(HRESULTAssertionTest, Streaming) { #endif // GTEST_OS_WINDOWS -#ifdef __BORLANDC__ -// Silences warnings: "Condition is always true", "Unreachable code" -# pragma option push -w-ccc -w-rch +// The following code intentionally tests a suboptimal syntax. +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdangling-else" +#pragma GCC diagnostic ignored "-Wempty-body" +#pragma GCC diagnostic ignored "-Wpragmas" #endif - // Tests that the assertion macros behave like single statements. TEST(AssertionSyntaxTest, BasicAssertionsBehavesLikeSingleStatement) { if (AlwaysFalse()) @@ -4155,6 +4157,9 @@ TEST(AssertionSyntaxTest, BasicAssertionsBehavesLikeSingleStatement) { else EXPECT_GT(3, 2) << ""; } +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif #if GTEST_HAS_EXCEPTIONS // Tests that the compiler will not complain about unreachable code in the @@ -4175,6 +4180,13 @@ TEST(ExpectThrowTest, DoesNotGenerateDuplicateCatchClauseWarning) { EXPECT_THROW(throw std::exception(), std::exception); } +// The following code intentionally tests a suboptimal syntax. +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdangling-else" +#pragma GCC diagnostic ignored "-Wempty-body" +#pragma GCC diagnostic ignored "-Wpragmas" +#endif TEST(AssertionSyntaxTest, ExceptionAssertionsBehavesLikeSingleStatement) { if (AlwaysFalse()) EXPECT_THROW(ThrowNothing(), bool); @@ -4200,8 +4212,19 @@ TEST(AssertionSyntaxTest, ExceptionAssertionsBehavesLikeSingleStatement) { else ; // NOLINT } +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif + #endif // GTEST_HAS_EXCEPTIONS +// The following code intentionally tests a suboptimal syntax. +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdangling-else" +#pragma GCC diagnostic ignored "-Wempty-body" +#pragma GCC diagnostic ignored "-Wpragmas" +#endif TEST(AssertionSyntaxTest, NoFatalFailureAssertionsBehavesLikeSingleStatement) { if (AlwaysFalse()) EXPECT_NO_FATAL_FAILURE(FAIL()) << "This should never be executed. " @@ -4224,6 +4247,9 @@ TEST(AssertionSyntaxTest, NoFatalFailureAssertionsBehavesLikeSingleStatement) { else ASSERT_NO_FATAL_FAILURE(SUCCEED()); } +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif // Tests that the assertion macros work well with switch statements. TEST(AssertionSyntaxTest, WorksWithSwitch) {