Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cpp/src/arrow/dataset/test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ class FileFormatScanMixin : public FileFormatFixtureMixin<FormatHelper>,
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();
Expand Down Expand Up @@ -690,7 +690,7 @@ class FileFormatScanMixin : public FileFormatFixtureMixin<FormatHelper>,
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();
Expand Down Expand Up @@ -739,7 +739,7 @@ class FileFormatScanMixin : public FileFormatFixtureMixin<FormatHelper>,
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();
Expand Down Expand Up @@ -787,7 +787,7 @@ class FileFormatScanMixin : public FileFormatFixtureMixin<FormatHelper>,
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();
Expand Down
31 changes: 30 additions & 1 deletion cpp/src/arrow/testing/matchers.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#pragma once

#include <utility>

#include <gmock/gmock-matchers.h>

#include "arrow/datum.h"
Expand All @@ -28,9 +30,36 @@

namespace arrow {

class PointeesEqualMatcher {
public:
template <typename PtrPair>
operator testing::Matcher<PtrPair>() const { // NOLINT runtime/explicit
struct Impl : testing::MatcherInterface<const PtrPair&> {
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<PtrPair>(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 <typename ResultMatcher>
class FutureMatcher {
Expand Down