From 4924e0610a89dcd58077a691a2e3702b0d6e58ed Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Wed, 28 Sep 2022 11:55:06 -0700 Subject: [PATCH 1/4] Moves boilerplate disabling copy constructor/assignment from GoogleTest's TEST_P macro into a header file to avoid triggering warnings in user code. Fixes #4015 PiperOrigin-RevId: 477513399 Change-Id: Ia21928ee12e85946b4c8db86835d225cb257eecc --- googletest/include/gtest/gtest-param-test.h | 7 +------ googletest/include/gtest/gtest.h | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/googletest/include/gtest/gtest-param-test.h b/googletest/include/gtest/gtest-param-test.h index b55119ac..19238ae4 100644 --- a/googletest/include/gtest/gtest-param-test.h +++ b/googletest/include/gtest/gtest-param-test.h @@ -409,7 +409,7 @@ internal::CartesianProductHolder Combine(const Generator&... g) { #define TEST_P(test_suite_name, test_name) \ class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \ - : public test_suite_name { \ + : public ::testing::internal::UserTestSuite { \ public: \ GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() {} \ void TestBody() override; \ @@ -429,11 +429,6 @@ internal::CartesianProductHolder Combine(const Generator&... g) { return 0; \ } \ static int gtest_registering_dummy_ GTEST_ATTRIBUTE_UNUSED_; \ - GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \ - (const GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) &) = delete; \ - GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) & operator=( \ - const GTEST_TEST_CLASS_NAME_(test_suite_name, \ - test_name) &) = delete; /* NOLINT */ \ }; \ int GTEST_TEST_CLASS_NAME_(test_suite_name, \ test_name)::gtest_registering_dummy_ = \ diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index d19a587a..6ff2774f 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -190,6 +190,21 @@ void ReportFailureInUnknownLocation(TestPartResult::Type result_type, const std::string& message); std::set* GetIgnoredParameterizedTestSuites(); +// Mix-in class for user tests. +// This allows us to add/delete members to/from test suites without having to +// modify the test macros themselves. +// This makes the code easier to read and maintain, as well making it easier +// for users to suppress any warnings originating from these members, as the +// members are now declared in an external header instead of in user code. +template +class UserTestSuite : public TestClass { + public: + UserTestSuite() = default; + UserTestSuite(const UserTestSuite &) = delete; + UserTestSuite &operator=(const UserTestSuite &) = delete; + virtual ~UserTestSuite() = default; +}; + } // namespace internal // The friend relationship of some of these classes is cyclic. From c43b916a9623e052860f59e52f71de1974ed8823 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Wed, 28 Sep 2022 14:14:25 -0700 Subject: [PATCH 2/4] Uses a simpler mechanism to disable the copying of GoogleTest test suites. PiperOrigin-RevId: 477549427 Change-Id: I6421ca09f0f1296cebdc3e54565049f1542dfa8a --- googletest/include/gtest/gtest-param-test.h | 2 +- googletest/include/gtest/gtest.h | 17 +++++------------ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/googletest/include/gtest/gtest-param-test.h b/googletest/include/gtest/gtest-param-test.h index 19238ae4..2dbac48e 100644 --- a/googletest/include/gtest/gtest-param-test.h +++ b/googletest/include/gtest/gtest-param-test.h @@ -409,7 +409,7 @@ internal::CartesianProductHolder Combine(const Generator&... g) { #define TEST_P(test_suite_name, test_name) \ class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \ - : public ::testing::internal::UserTestSuite { \ + : public test_suite_name, private ::testing::internal::NonCopyable { \ public: \ GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() {} \ void TestBody() override; \ diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index 6ff2774f..4f037ad7 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -190,19 +190,12 @@ void ReportFailureInUnknownLocation(TestPartResult::Type result_type, const std::string& message); std::set* GetIgnoredParameterizedTestSuites(); -// Mix-in class for user tests. -// This allows us to add/delete members to/from test suites without having to -// modify the test macros themselves. -// This makes the code easier to read and maintain, as well making it easier -// for users to suppress any warnings originating from these members, as the -// members are now declared in an external header instead of in user code. -template -class UserTestSuite : public TestClass { +class NonCopyable { public: - UserTestSuite() = default; - UserTestSuite(const UserTestSuite &) = delete; - UserTestSuite &operator=(const UserTestSuite &) = delete; - virtual ~UserTestSuite() = default; + NonCopyable() = default; + NonCopyable(const NonCopyable &) = delete; + NonCopyable &operator=(const NonCopyable &) = delete; + ~NonCopyable() = default; }; } // namespace internal From 19387c9dd5b153a6bdef6f1fc4fb2391fdb122d0 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Wed, 28 Sep 2022 14:58:29 -0700 Subject: [PATCH 3/4] Rollback: Uses a simpler mechanism to disable the copying of GoogleTest test suites. PiperOrigin-RevId: 477560280 Change-Id: I1c1f5a1d6645859ec38cb1a75cd267816d2aff35 --- googletest/include/gtest/gtest-param-test.h | 2 +- googletest/include/gtest/gtest.h | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/googletest/include/gtest/gtest-param-test.h b/googletest/include/gtest/gtest-param-test.h index 2dbac48e..19238ae4 100644 --- a/googletest/include/gtest/gtest-param-test.h +++ b/googletest/include/gtest/gtest-param-test.h @@ -409,7 +409,7 @@ internal::CartesianProductHolder Combine(const Generator&... g) { #define TEST_P(test_suite_name, test_name) \ class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \ - : public test_suite_name, private ::testing::internal::NonCopyable { \ + : public ::testing::internal::UserTestSuite { \ public: \ GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() {} \ void TestBody() override; \ diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index 4f037ad7..6ff2774f 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -190,12 +190,19 @@ void ReportFailureInUnknownLocation(TestPartResult::Type result_type, const std::string& message); std::set* GetIgnoredParameterizedTestSuites(); -class NonCopyable { +// Mix-in class for user tests. +// This allows us to add/delete members to/from test suites without having to +// modify the test macros themselves. +// This makes the code easier to read and maintain, as well making it easier +// for users to suppress any warnings originating from these members, as the +// members are now declared in an external header instead of in user code. +template +class UserTestSuite : public TestClass { public: - NonCopyable() = default; - NonCopyable(const NonCopyable &) = delete; - NonCopyable &operator=(const NonCopyable &) = delete; - ~NonCopyable() = default; + UserTestSuite() = default; + UserTestSuite(const UserTestSuite &) = delete; + UserTestSuite &operator=(const UserTestSuite &) = delete; + virtual ~UserTestSuite() = default; }; } // namespace internal From d1a0039b97291dd1dc14f123b906bb7622ffe07c Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Wed, 28 Sep 2022 15:24:12 -0700 Subject: [PATCH 4/4] Rollback: Moves boilerplate disabling copy constructor/assignment from GoogleTest's TEST_P macro into a header file to avoid triggering warnings in user code. PiperOrigin-RevId: 477566426 Change-Id: Ia417e295d839f43be6e61a5699457866108f2a01 --- googletest/include/gtest/gtest-param-test.h | 7 ++++++- googletest/include/gtest/gtest.h | 15 --------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/googletest/include/gtest/gtest-param-test.h b/googletest/include/gtest/gtest-param-test.h index 19238ae4..b55119ac 100644 --- a/googletest/include/gtest/gtest-param-test.h +++ b/googletest/include/gtest/gtest-param-test.h @@ -409,7 +409,7 @@ internal::CartesianProductHolder Combine(const Generator&... g) { #define TEST_P(test_suite_name, test_name) \ class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \ - : public ::testing::internal::UserTestSuite { \ + : public test_suite_name { \ public: \ GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() {} \ void TestBody() override; \ @@ -429,6 +429,11 @@ internal::CartesianProductHolder Combine(const Generator&... g) { return 0; \ } \ static int gtest_registering_dummy_ GTEST_ATTRIBUTE_UNUSED_; \ + GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \ + (const GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) &) = delete; \ + GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) & operator=( \ + const GTEST_TEST_CLASS_NAME_(test_suite_name, \ + test_name) &) = delete; /* NOLINT */ \ }; \ int GTEST_TEST_CLASS_NAME_(test_suite_name, \ test_name)::gtest_registering_dummy_ = \ diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index 6ff2774f..d19a587a 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -190,21 +190,6 @@ void ReportFailureInUnknownLocation(TestPartResult::Type result_type, const std::string& message); std::set* GetIgnoredParameterizedTestSuites(); -// Mix-in class for user tests. -// This allows us to add/delete members to/from test suites without having to -// modify the test macros themselves. -// This makes the code easier to read and maintain, as well making it easier -// for users to suppress any warnings originating from these members, as the -// members are now declared in an external header instead of in user code. -template -class UserTestSuite : public TestClass { - public: - UserTestSuite() = default; - UserTestSuite(const UserTestSuite &) = delete; - UserTestSuite &operator=(const UserTestSuite &) = delete; - virtual ~UserTestSuite() = default; -}; - } // namespace internal // The friend relationship of some of these classes is cyclic.