From 51dda5465257dc2fe76f0e94ba5d98c592c9a779 Mon Sep 17 00:00:00 2001 From: Brad House Date: Wed, 4 Sep 2024 14:07:38 -0400 Subject: [PATCH] try to fix compat with googletest 1.15 (#874) Due to running containerized tests we had to cut and paste the `TEST_P` macro definition in `googletest/include/gtest/gtest-param-test.h`, and modify it as it isn't designed to be wrapped in any way. Unfortunately this tends to change from release to release, usually in minor ways ... but also google test specifically doesn't advertise its own version so it can be hard to work around. Lets try to fix compatibility with google test 1.15 Fixes #873 Authored-By: Brad House (@bradh352) --- test/ares-test.h | 94 ++++++++++++++++++++++++++---------------------- 1 file changed, 51 insertions(+), 43 deletions(-) diff --git a/test/ares-test.h b/test/ares-test.h index cef98d24..8dbb28e5 100644 --- a/test/ares-test.h +++ b/test/ares-test.h @@ -763,49 +763,57 @@ int RunInContainer(ContainerFilesystem *fs, const std::string &hostname, } \ int ICLASS_NAME(casename, testname)::InnerTestBody() -#define CONTAINED_TEST_P(test_suite_name, test_name, hostname, domainname, files) \ - class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \ - : public test_suite_name { \ - public: \ - GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() {} \ - int InnerTestBody(); \ - void TestBody() \ - { \ - ContainerFilesystem chroot(files, ".."); \ - VoidToIntFn fn = \ - [this](void) -> int { \ - ares_reinit(this->channel_); \ - ares_sleep_time(100); \ - return this->InnerTestBody(); \ - }; \ - EXPECT_EQ(0, RunInContainer(&chroot, hostname, domainname, fn)); \ - } \ - \ - private: \ - static int AddToRegistry() { \ - ::testing::UnitTest::GetInstance() \ - ->parameterized_test_registry() \ - .GetTestSuitePatternHolder( \ - GTEST_STRINGIFY_(test_suite_name), \ - ::testing::internal::CodeLocation(__FILE__, __LINE__)) \ - ->AddTestPattern( \ - GTEST_STRINGIFY_(test_suite_name), GTEST_STRINGIFY_(test_name), \ - new ::testing::internal::TestMetaFactory(), \ - ::testing::internal::CodeLocation(__FILE__, __LINE__)); \ - 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_ = \ - GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)::AddToRegistry(); \ - int GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)::InnerTestBody() +/* Derived from googletest/include/gtest/gtest-param-test.h, specifically the + * TEST_P() macro, and some fixes to try to be compatible with different + * versions. */ +#ifndef GTEST_ATTRIBUTE_UNUSED_ +# define GTEST_ATTRIBUTE_UNUSED_ +#endif +#ifndef GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED +# define GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED +#endif +# define CONTAINED_TEST_P(test_suite_name, test_name, hostname, domainname, \ + files) \ + class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \ + : public test_suite_name { \ + public: \ + GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() \ + { \ + } \ + int InnerTestBody(); \ + void TestBody() \ + { \ + ContainerFilesystem chroot(files, ".."); \ + VoidToIntFn fn = [this](void) -> int { \ + ares_reinit(this->channel_); \ + ares_sleep_time(100); \ + return this->InnerTestBody(); \ + }; \ + EXPECT_EQ(0, RunInContainer(&chroot, hostname, domainname, fn)); \ + } \ + \ + private: \ + static int AddToRegistry() \ + { \ + ::testing::UnitTest::GetInstance() \ + ->parameterized_test_registry() \ + .GetTestSuitePatternHolder( \ + GTEST_STRINGIFY_(test_suite_name), \ + ::testing::internal::CodeLocation(__FILE__, __LINE__)) \ + ->AddTestPattern( \ + GTEST_STRINGIFY_(test_suite_name), GTEST_STRINGIFY_(test_name), \ + new ::testing::internal::TestMetaFactory(), \ + ::testing::internal::CodeLocation(__FILE__, __LINE__)); \ + return 0; \ + } \ + GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED static int \ + gtest_registering_dummy_ GTEST_ATTRIBUTE_UNUSED_; \ + }; \ + int GTEST_TEST_CLASS_NAME_(test_suite_name, \ + test_name)::gtest_registering_dummy_ = \ + GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)::AddToRegistry(); \ + int GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)::InnerTestBody() #endif