9#ifndef LLVM_TESTING_SUPPORT_ERROR_H
10#define LLVM_TESTING_SUPPORT_ERROR_H
15#include "gmock/gmock.h"
32 :
public testing::MatcherInterface<const ExpectedHolder<T> &> {
38 testing::MatchResultListener *listener)
const override {
42 bool result = Matcher.MatchAndExplain(*Holder.
Exp, listener);
44 if (result || !listener->IsInterested())
47 Matcher.DescribeNegationTo(listener->stream());
53 *
OS <<
"succeeded with value (";
54 Matcher.DescribeTo(
OS);
59 *
OS <<
"did not succeed or value (";
60 Matcher.DescribeNegationTo(
OS);
65 testing::Matcher<T> Matcher;
74 operator testing::Matcher<const ExpectedHolder<T> &>()
const {
83template <
typename InfoT>
87 : Matcher(
std::
move(Matcher)) {}
90 testing::MatchResultListener *listener)
const override {
94 if (Holder.
Infos.size() > 1) {
95 *listener <<
"multiple errors";
100 if (!
Info.isA<InfoT>()) {
101 *listener <<
"Error was not of given type";
108 return Matcher->MatchAndExplain(
static_cast<InfoT &
>(
Info), listener);
112 *
OS <<
"failed with Error of given type";
114 *
OS <<
" and the error ";
115 Matcher->DescribeTo(
OS);
120 *
OS <<
"succeeded or did not fail with the error of given type";
122 *
OS <<
" or the error ";
123 Matcher->DescribeNegationTo(
OS);
128 std::optional<testing::Matcher<InfoT &>> Matcher;
132 :
public testing::MatcherInterface<const ErrorHolder &> {
135 testing::Matcher<std::vector<std::string>> Matcher)
136 : Matcher(
std::
move(Matcher)) {}
139 testing::MatchResultListener *listener)
const override {
140 std::vector<std::string> Messages;
141 Messages.reserve(Holder.
Infos.size());
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)
194MATCHER(Succeeded,
"") {
return arg.Success(); }
197template <
typename InfoT>
198testing::Matcher<const detail::ErrorHolder &>
Failed() {
202template <
typename InfoT,
typename M>
203testing::Matcher<const detail::ErrorHolder &>
Failed(M Matcher) {
205 testing::SafeMatcherCast<InfoT &>(Matcher)));
208template <
typename... M>
210 static_assert(
sizeof...(M) > 0);
Analysis containing CSE Info
Tagged union holding either a T or a Error.
ErrorMatchesMono(std::optional< testing::Matcher< InfoT & > > Matcher)
void DescribeNegationTo(std::ostream *OS) const override
bool MatchAndExplain(const ErrorHolder &Holder, testing::MatchResultListener *listener) const override
void DescribeTo(std::ostream *OS) const override
ErrorMessageMatches(testing::Matcher< std::vector< std::string > > Matcher)
void DescribeTo(std::ostream *OS) const override
bool MatchAndExplain(const ErrorHolder &Holder, testing::MatchResultListener *listener) const override
void DescribeNegationTo(std::ostream *OS) const override
bool MatchAndExplain(const ExpectedHolder< T > &Holder, testing::MatchResultListener *listener) const override
void DescribeNegationTo(std::ostream *OS) const override
void DescribeTo(std::ostream *OS) const override
ValueMatchesMono(const testing::Matcher< T > &Matcher)
ValueMatchesPoly(const M &Matcher)
ExpectedHolder< T > TakeExpected(Expected< T > &Exp)
ErrorHolder TakeError(Error Err)
This is an optimization pass for GlobalISel generic memory operations.
testing::Matcher< const detail::ErrorHolder & > FailedWithMessageArray(M Matcher)
testing::Matcher< const detail::ErrorHolder & > Failed()
testing::Matcher< const detail::ErrorHolder & > FailedWithMessage(M... Matcher)
detail::ValueMatchesPoly< M > HasValue(M Matcher)
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Implement std::hash so that hash_code can be used in STL containers.
std::vector< std::shared_ptr< ErrorInfoBase > > Infos