Skip to content

Commit cd30dea

Browse files
committed
ARROW-15358: [C++] Fix custom matcher compilation
Closes apache#12181 from pitrou/ARROW-15358-matcher-compilation Authored-by: Antoine Pitrou <antoine@python.org> Signed-off-by: Antoine Pitrou <antoine@python.org>
1 parent e28b3a0 commit cd30dea

2 files changed

Lines changed: 34 additions & 5 deletions

File tree

cpp/src/arrow/dataset/test_util.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ class FileFormatScanMixin : public FileFormatFixtureMixin<FormatHelper>,
645645
row_count += batch->num_rows();
646646
ASSERT_THAT(
647647
batch->schema()->fields(),
648-
::testing::UnorderedPointwise(PointeesEquals(), expected_schema->fields()))
648+
::testing::UnorderedPointwise(PointeesEqual(), expected_schema->fields()))
649649
<< "EXPECTED:\n"
650650
<< expected_schema->ToString() << "\nACTUAL:\n"
651651
<< batch->schema()->ToString();
@@ -690,7 +690,7 @@ class FileFormatScanMixin : public FileFormatFixtureMixin<FormatHelper>,
690690
row_count += batch->num_rows();
691691
ASSERT_THAT(
692692
batch->schema()->fields(),
693-
::testing::UnorderedPointwise(PointeesEquals(), physical_schema->fields()))
693+
::testing::UnorderedPointwise(PointeesEqual(), physical_schema->fields()))
694694
<< "EXPECTED:\n"
695695
<< physical_schema->ToString() << "\nACTUAL:\n"
696696
<< batch->schema()->ToString();
@@ -739,7 +739,7 @@ class FileFormatScanMixin : public FileFormatFixtureMixin<FormatHelper>,
739739
row_count += batch->num_rows();
740740
ASSERT_THAT(
741741
batch->schema()->fields(),
742-
::testing::UnorderedPointwise(PointeesEquals(), physical_schema->fields()))
742+
::testing::UnorderedPointwise(PointeesEqual(), physical_schema->fields()))
743743
<< "EXPECTED:\n"
744744
<< physical_schema->ToString() << "\nACTUAL:\n"
745745
<< batch->schema()->ToString();
@@ -787,7 +787,7 @@ class FileFormatScanMixin : public FileFormatFixtureMixin<FormatHelper>,
787787
row_count += batch->num_rows();
788788
ASSERT_THAT(
789789
batch->schema()->fields(),
790-
::testing::UnorderedPointwise(PointeesEquals(), expected_schema->fields()))
790+
::testing::UnorderedPointwise(PointeesEqual(), expected_schema->fields()))
791791
<< "EXPECTED:\n"
792792
<< expected_schema->ToString() << "\nACTUAL:\n"
793793
<< batch->schema()->ToString();

cpp/src/arrow/testing/matchers.h

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
#pragma once
1919

20+
#include <utility>
21+
2022
#include <gmock/gmock-matchers.h>
2123

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

2931
namespace arrow {
3032

33+
class PointeesEqualMatcher {
34+
public:
35+
template <typename PtrPair>
36+
operator testing::Matcher<PtrPair>() const { // NOLINT runtime/explicit
37+
struct Impl : testing::MatcherInterface<const PtrPair&> {
38+
void DescribeTo(::std::ostream* os) const override { *os << "pointees are equal"; }
39+
40+
void DescribeNegationTo(::std::ostream* os) const override {
41+
*os << "pointees are not equal";
42+
}
43+
44+
bool MatchAndExplain(const PtrPair& pair,
45+
testing::MatchResultListener* listener) const override {
46+
const auto& first = *std::get<0>(pair);
47+
const auto& second = *std::get<1>(pair);
48+
const bool match = first.Equals(second);
49+
*listener << "whose pointees " << testing::PrintToString(first) << " and "
50+
<< testing::PrintToString(second)
51+
<< (match ? " are equal" : " are not equal");
52+
return match;
53+
}
54+
};
55+
56+
return testing::Matcher<PtrPair>(new Impl());
57+
}
58+
};
59+
3160
// A matcher that checks that the values pointed to are Equals().
3261
// Useful in conjunction with other googletest matchers.
33-
MATCHER(PointeesEquals, "") { return std::get<0>(arg)->Equals(*std::get<1>(arg)); }
62+
inline PointeesEqualMatcher PointeesEqual() { return {}; }
3463

3564
template <typename ResultMatcher>
3665
class FutureMatcher {

0 commit comments

Comments
 (0)