diff --git a/cpp/src/arrow/dataset/test_util.h b/cpp/src/arrow/dataset/test_util.h index 5128021bf65..3f826fa09c9 100644 --- a/cpp/src/arrow/dataset/test_util.h +++ b/cpp/src/arrow/dataset/test_util.h @@ -645,7 +645,7 @@ class FileFormatScanMixin : public FileFormatFixtureMixin, row_count += batch->num_rows(); ASSERT_THAT( batch->schema()->fields(), - ::testing::UnorderedPointwise(PointeesEquals(), expected_schema->fields())) + ::testing::UnorderedPointwise(PointeesEqual(), expected_schema->fields())) << "EXPECTED:\n" << expected_schema->ToString() << "\nACTUAL:\n" << batch->schema()->ToString(); @@ -690,7 +690,7 @@ class FileFormatScanMixin : public FileFormatFixtureMixin, row_count += batch->num_rows(); ASSERT_THAT( batch->schema()->fields(), - ::testing::UnorderedPointwise(PointeesEquals(), physical_schema->fields())) + ::testing::UnorderedPointwise(PointeesEqual(), physical_schema->fields())) << "EXPECTED:\n" << physical_schema->ToString() << "\nACTUAL:\n" << batch->schema()->ToString(); @@ -739,7 +739,7 @@ class FileFormatScanMixin : public FileFormatFixtureMixin, row_count += batch->num_rows(); ASSERT_THAT( batch->schema()->fields(), - ::testing::UnorderedPointwise(PointeesEquals(), physical_schema->fields())) + ::testing::UnorderedPointwise(PointeesEqual(), physical_schema->fields())) << "EXPECTED:\n" << physical_schema->ToString() << "\nACTUAL:\n" << batch->schema()->ToString(); @@ -787,7 +787,7 @@ class FileFormatScanMixin : public FileFormatFixtureMixin, row_count += batch->num_rows(); ASSERT_THAT( batch->schema()->fields(), - ::testing::UnorderedPointwise(PointeesEquals(), expected_schema->fields())) + ::testing::UnorderedPointwise(PointeesEqual(), expected_schema->fields())) << "EXPECTED:\n" << expected_schema->ToString() << "\nACTUAL:\n" << batch->schema()->ToString(); diff --git a/cpp/src/arrow/testing/matchers.h b/cpp/src/arrow/testing/matchers.h index 1ffc2e1d9fa..ddfe60f1740 100644 --- a/cpp/src/arrow/testing/matchers.h +++ b/cpp/src/arrow/testing/matchers.h @@ -17,6 +17,8 @@ #pragma once +#include + #include #include "arrow/datum.h" @@ -28,9 +30,36 @@ namespace arrow { +class PointeesEqualMatcher { + public: + template + operator testing::Matcher() const { // NOLINT runtime/explicit + struct Impl : testing::MatcherInterface { + void DescribeTo(::std::ostream* os) const override { *os << "pointees are equal"; } + + void DescribeNegationTo(::std::ostream* os) const override { + *os << "pointees are not equal"; + } + + bool MatchAndExplain(const PtrPair& pair, + testing::MatchResultListener* listener) const override { + const auto& first = *std::get<0>(pair); + const auto& second = *std::get<1>(pair); + const bool match = first.Equals(second); + *listener << "whose pointees " << testing::PrintToString(first) << " and " + << testing::PrintToString(second) + << (match ? " are equal" : " are not equal"); + return match; + } + }; + + return testing::Matcher(new Impl()); + } +}; + // A matcher that checks that the values pointed to are Equals(). // Useful in conjunction with other googletest matchers. -MATCHER(PointeesEquals, "") { return std::get<0>(arg)->Equals(*std::get<1>(arg)); } +inline PointeesEqualMatcher PointeesEqual() { return {}; } template class FutureMatcher {