Skip to content

Commit

Permalink
Allow compilation with any GTest version 1.11+ (#13153)
Browse files Browse the repository at this point in the history
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: #13153
  • Loading branch information
robertmaynard authored Apr 18, 2023
1 parent feea040 commit 1750bff
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 22 deletions.
7 changes: 6 additions & 1 deletion cpp/include/cudf_test/cudf_gtest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,6 +35,10 @@
*/

// @cond
#if __has_include(<gtest/internal/gtest-type-util.h.pump>)
// 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
Expand Down Expand Up @@ -89,6 +93,7 @@ struct TypeList<Types<TYPES...>> {

} // namespace internal
} // namespace testing
#endif // gtest < 1.11
// @endcond

#include <gmock/gmock.h>
Expand Down
12 changes: 5 additions & 7 deletions cpp/include/cudf_test/type_list_utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,12 @@ template <class... T, int D>
struct GetTypeImpl<Types<T...>, D> {
static_assert(D < sizeof...(T), "Out of bounds");

using type = typename GetTypeImpl<typename Types<T...>::Tail, D - 1>::type;
using raw_type = decltype(std::get<D>(std::declval<std::tuple<T...>>()));
using type = std::decay_t<raw_type>;
};

template <class... ARGS>
struct GetTypeImpl<Types<ARGS...>, 0> {
static_assert(sizeof...(ARGS) > 0, "Out of bounds");

using type = typename Types<ARGS...>::Head;
template <class T, class... ARGS>
struct GetTypeImpl<Types<T, ARGS...>, 0> {
using type = T;
};
// @endcond

Expand Down
17 changes: 10 additions & 7 deletions cpp/tests/iterator/optional_iterator_test_numeric.cu
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename T>
std::ostream& operator<<(std::ostream& os, cudf::meanvar<T> const& rhs)
{
return os << "[" << rhs.value << ", " << rhs.value_squared << ", " << rhs.count << "] ";
};
} // namespace cudf

template <typename T>
struct NumericOptionalIteratorTest : public IteratorTest<T> {};

Expand All @@ -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 <typename T>
std::ostream& operator<<(std::ostream& os, cudf::meanvar<T> const& rhs)
{
return os << "[" << rhs.value << ", " << rhs.value_squared << ", " << rhs.count << "] ";
};

// Transformers and Operators for optional_iterator test
template <typename ElementType>
struct transformer_optional_meanvar {
Expand Down
17 changes: 10 additions & 7 deletions cpp/tests/iterator/pair_iterator_test_numeric.cu
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,23 @@

using TestingTypes = cudf::test::NumericTypes;

namespace cudf {
// To print meanvar for debug.
// Needs to be in the cudf namespace for ADL
template <typename T>
std::ostream& operator<<(std::ostream& os, cudf::meanvar<T> const& rhs)
{
return os << "[" << rhs.value << ", " << rhs.value_squared << ", " << rhs.count << "] ";
};
} // namespace cudf

template <typename T>
struct NumericPairIteratorTest : public IteratorTest<T> {};

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 <typename T>
std::ostream& operator<<(std::ostream& os, cudf::meanvar<T> const& rhs)
{
return os << "[" << rhs.value << ", " << rhs.value_squared << ", " << rhs.count << "] ";
};

// Transformers and Operators for pair_iterator test
template <typename ElementType>
struct transformer_pair_meanvar {
Expand Down

0 comments on commit 1750bff

Please sign in to comment.