9 #ifndef LLVM_TESTING_SUPPORT_ERROR_H
10 #define LLVM_TESTING_SUPPORT_ERROR_H
16 #include "gmock/gmock.h"
33 :
public testing::MatcherInterface<const ExpectedHolder<T> &> {
39 testing::MatchResultListener *listener)
const override {
43 bool result = Matcher.MatchAndExplain(*Holder.
Exp, listener);
45 if (
result || !listener->IsInterested())
48 Matcher.DescribeNegationTo(listener->stream());
54 *OS <<
"succeeded with value (";
55 Matcher.DescribeTo(OS);
60 *OS <<
"did not succeed or value (";
61 Matcher.DescribeNegationTo(OS);
66 testing::Matcher<T> Matcher;
75 operator testing::Matcher<const ExpectedHolder<T> &>()
const {
84 template <
typename InfoT>
88 : Matcher(
std::
move(Matcher)) {}
91 testing::MatchResultListener *listener)
const override {
95 if (Holder.
Infos.size() > 1) {
96 *listener <<
"multiple errors";
101 if (!
Info.isA<InfoT>()) {
102 *listener <<
"Error was not of given type";
109 return Matcher->MatchAndExplain(
static_cast<InfoT &
>(
Info), listener);
113 *OS <<
"failed with Error of given type";
115 *OS <<
" and the error ";
116 Matcher->DescribeTo(OS);
121 *OS <<
"succeeded or did not fail with the error of given type";
123 *OS <<
" or the error ";
124 Matcher->DescribeNegationTo(OS);
133 :
public testing::MatcherInterface<const ErrorHolder &> {
136 testing::Matcher<std::vector<std::string>> Matcher)
137 : Matcher(
std::
move(Matcher)) {}
140 testing::MatchResultListener *listener)
const override {
141 std::vector<std::string> Messages;
142 for (
const std::shared_ptr<ErrorInfoBase> &
Info: Holder.
Infos)
143 Messages.push_back(
Info->message());
145 return Matcher.MatchAndExplain(Messages, listener);
149 *OS <<
"failed with Error whose message ";
150 Matcher.DescribeTo(OS);
154 *OS <<
"failed with an Error whose message ";
155 Matcher.DescribeNegationTo(OS);
159 testing::Matcher<std::vector<std::string>> Matcher;
163 #define EXPECT_THAT_ERROR(Err, Matcher) \
164 EXPECT_THAT(llvm::detail::TakeError(Err), Matcher)
165 #define ASSERT_THAT_ERROR(Err, Matcher) \
166 ASSERT_THAT(llvm::detail::TakeError(Err), Matcher)
189 #define EXPECT_THAT_EXPECTED(Err, Matcher) \
190 EXPECT_THAT(llvm::detail::TakeExpected(Err), Matcher)
191 #define ASSERT_THAT_EXPECTED(Err, Matcher) \
192 ASSERT_THAT(llvm::detail::TakeExpected(Err), Matcher)
194 MATCHER(Succeeded,
"") {
return arg.Success(); }
197 template <
typename InfoT>
198 testing::Matcher<const detail::ErrorHolder &>
Failed() {
202 template <
typename InfoT,
typename M>
203 testing::Matcher<const detail::ErrorHolder &>
Failed(M Matcher) {
205 testing::SafeMatcherCast<InfoT &>(Matcher)));
208 template <
typename...
M>
210 static_assert(
sizeof...(
M) > 0,
"");
215 template <
typename M>
220 template <
typename M>