From 80c210040afbe95f63dc67b2246b75a930807aa0 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Tue, 18 Apr 2023 10:46:15 -0400 Subject: [PATCH] Allow compilation with any GTest version 1.11+ (#13153) GTest max support for `Types` was removed in 1.11, so we remove the workarounds in cudf_gtest. Since we need to support our custom `Types` and the GTest 1.11+ version rework the type_list_utilities to be generic and not depend on specific traits. Also corrected the `<<` overloads for GTest printing so that they work with GTest 1.11. Authors: - Robert Maynard (https://github.com/robertmaynard) - Vukasin Milovanovic (https://github.com/vuule) Approvers: - Bradley Dice (https://github.com/bdice) - Nghia Truong (https://github.com/ttnghia) URL: https://github.com/rapidsai/cudf/pull/13153 --- cpp/include/cudf_test/cudf_gtest.hpp | 7 ++++++- cpp/include/cudf_test/type_list_utilities.hpp | 12 +++++------- .../iterator/optional_iterator_test_numeric.cu | 17 ++++++++++------- .../iterator/pair_iterator_test_numeric.cu | 17 ++++++++++------- 4 files changed, 31 insertions(+), 22 deletions(-) diff --git a/cpp/include/cudf_test/cudf_gtest.hpp b/cpp/include/cudf_test/cudf_gtest.hpp index 46d29902987..36ab2e02aed 100644 --- a/cpp/include/cudf_test/cudf_gtest.hpp +++ b/cpp/include/cudf_test/cudf_gtest.hpp @@ -22,7 +22,7 @@ /** * @file cudf_gtest.hpp - * @brief Work around for GTests emulation of variadic templates in + * @brief Work around for GTests( <=v1.10 ) emulation of variadic templates in * @verbatim ::Testing::Types @endverbatim * * @note Instead of including `gtest/gtest.h`, all libcudf test files should @@ -35,6 +35,10 @@ */ // @cond +#if __has_include() +// gtest doesn't provide a version header so we need to +// use a file existence trick. +// gtest-type-util.h.pump only exists in versions < 1.11 #define Types Types_NOT_USED #define Types0 Types0_NOT_USED #define TypeList TypeList_NOT_USED @@ -89,6 +93,7 @@ struct TypeList> { } // namespace internal } // namespace testing +#endif // gtest < 1.11 // @endcond #include diff --git a/cpp/include/cudf_test/type_list_utilities.hpp b/cpp/include/cudf_test/type_list_utilities.hpp index c3ba90e0a64..b069a34afb8 100644 --- a/cpp/include/cudf_test/type_list_utilities.hpp +++ b/cpp/include/cudf_test/type_list_utilities.hpp @@ -90,14 +90,12 @@ template struct GetTypeImpl, D> { static_assert(D < sizeof...(T), "Out of bounds"); - using type = typename GetTypeImpl::Tail, D - 1>::type; + using raw_type = decltype(std::get(std::declval>())); + using type = std::decay_t; }; - -template -struct GetTypeImpl, 0> { - static_assert(sizeof...(ARGS) > 0, "Out of bounds"); - - using type = typename Types::Head; +template +struct GetTypeImpl, 0> { + using type = T; }; // @endcond diff --git a/cpp/tests/iterator/optional_iterator_test_numeric.cu b/cpp/tests/iterator/optional_iterator_test_numeric.cu index 0373d4af259..b6c68ce062e 100644 --- a/cpp/tests/iterator/optional_iterator_test_numeric.cu +++ b/cpp/tests/iterator/optional_iterator_test_numeric.cu @@ -24,6 +24,16 @@ using TestingTypes = cudf::test::NumericTypes; +namespace cudf { +// To print meanvar for debug. +// Needs to be in the cudf namespace for ADL +template +std::ostream& operator<<(std::ostream& os, cudf::meanvar const& rhs) +{ + return os << "[" << rhs.value << ", " << rhs.value_squared << ", " << rhs.count << "] "; +}; +} // namespace cudf + template struct NumericOptionalIteratorTest : public IteratorTest {}; @@ -34,13 +44,6 @@ TYPED_TEST(NumericOptionalIteratorTest, nonull_optional_iterator) } TYPED_TEST(NumericOptionalIteratorTest, null_optional_iterator) { null_optional_iterator(*this); } -// to print meanvar for debug. -template -std::ostream& operator<<(std::ostream& os, cudf::meanvar const& rhs) -{ - return os << "[" << rhs.value << ", " << rhs.value_squared << ", " << rhs.count << "] "; -}; - // Transformers and Operators for optional_iterator test template struct transformer_optional_meanvar { diff --git a/cpp/tests/iterator/pair_iterator_test_numeric.cu b/cpp/tests/iterator/pair_iterator_test_numeric.cu index 6a6d55f9557..1483abcf860 100644 --- a/cpp/tests/iterator/pair_iterator_test_numeric.cu +++ b/cpp/tests/iterator/pair_iterator_test_numeric.cu @@ -22,6 +22,16 @@ using TestingTypes = cudf::test::NumericTypes; +namespace cudf { +// To print meanvar for debug. +// Needs to be in the cudf namespace for ADL +template +std::ostream& operator<<(std::ostream& os, cudf::meanvar const& rhs) +{ + return os << "[" << rhs.value << ", " << rhs.value_squared << ", " << rhs.count << "] "; +}; +} // namespace cudf + template struct NumericPairIteratorTest : public IteratorTest {}; @@ -29,13 +39,6 @@ TYPED_TEST_SUITE(NumericPairIteratorTest, TestingTypes); TYPED_TEST(NumericPairIteratorTest, nonull_pair_iterator) { nonull_pair_iterator(*this); } TYPED_TEST(NumericPairIteratorTest, null_pair_iterator) { null_pair_iterator(*this); } -// to print meanvar for debug. -template -std::ostream& operator<<(std::ostream& os, cudf::meanvar const& rhs) -{ - return os << "[" << rhs.value << ", " << rhs.value_squared << ", " << rhs.count << "] "; -}; - // Transformers and Operators for pair_iterator test template struct transformer_pair_meanvar {