llvm/llvm/include/llvm/Testing/Support/Error.h

//===- llvm/Testing/Support/Error.h ---------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_TESTING_SUPPORT_ERROR_H
#define LLVM_TESTING_SUPPORT_ERROR_H

#include "llvm/Support/Error.h"
#include "llvm/Testing/Support/SupportHelpers.h"

#include "gmock/gmock.h"
#include <ostream>

namespace llvm {
namespace detail {
ErrorHolder TakeError(Error Err);

template <typename T> ExpectedHolder<T> TakeExpected(Expected<T> &Exp) {}

template <typename T> ExpectedHolder<T> TakeExpected(Expected<T> &&Exp) {}

template <typename T>
class ValueMatchesMono
    : public testing::MatcherInterface<const ExpectedHolder<T> &> {};

template<typename M>
class ValueMatchesPoly {};

template <typename InfoT>
class ErrorMatchesMono : public testing::MatcherInterface<const ErrorHolder &> {};

class ErrorMessageMatches
    : public testing::MatcherInterface<const ErrorHolder &> {};
} // namespace detail

#define EXPECT_THAT_ERROR(Err, Matcher)
#define ASSERT_THAT_ERROR(Err, Matcher)

/// Helper macro for checking the result of an 'Expected<T>'
///
///   @code{.cpp}
///     // function to be tested
///     Expected<int> myDivide(int A, int B);
///
///     TEST(myDivideTests, GoodAndBad) {
///       // test good case
///       // if you only care about success or failure:
///       EXPECT_THAT_EXPECTED(myDivide(10, 5), Succeeded());
///       // if you also care about the value:
///       EXPECT_THAT_EXPECTED(myDivide(10, 5), HasValue(2));
///
///       // test the error case
///       EXPECT_THAT_EXPECTED(myDivide(10, 0), Failed());
///       // also check the error message
///       EXPECT_THAT_EXPECTED(myDivide(10, 0),
///           FailedWithMessage("B must not be zero!"));
///     }
///   @endcode

#define EXPECT_THAT_EXPECTED(Err, Matcher)
#define ASSERT_THAT_EXPECTED(Err, Matcher)

MATCHER(Succeeded, "") {}
MATCHER(Failed, "") {}

template <typename InfoT>
testing::Matcher<const detail::ErrorHolder &> Failed() {}

template <typename InfoT, typename M>
testing::Matcher<const detail::ErrorHolder &> Failed(M Matcher) {}

template <typename... M>
testing::Matcher<const detail::ErrorHolder &> FailedWithMessage(M... Matcher) {}

template <typename M>
testing::Matcher<const detail::ErrorHolder &> FailedWithMessageArray(M Matcher) {}

template <typename M>
detail::ValueMatchesPoly<M> HasValue(M Matcher) {}

} // namespace llvm

#endif