LCOV - code coverage report
Current view: top level - include/llvm/Testing/Support - Error.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 13 15 86.7 %
Date: 2017-09-14 15:23:50 Functions: 23 59 39.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- llvm/Testing/Support/Error.h ---------------------------------------===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : 
      10             : #ifndef LLVM_TESTING_SUPPORT_ERROR_H
      11             : #define LLVM_TESTING_SUPPORT_ERROR_H
      12             : 
      13             : #include "llvm/ADT/Optional.h"
      14             : #include "llvm/Support/Error.h"
      15             : #include "llvm/Testing/Support/SupportHelpers.h"
      16             : 
      17             : #include "gmock/gmock.h"
      18             : #include <ostream>
      19             : 
      20             : namespace llvm {
      21             : namespace detail {
      22             : ErrorHolder TakeError(Error Err);
      23             : 
      24          81 : template <typename T> ExpectedHolder<T> TakeExpected(Expected<T> &Exp) {
      25          81 :   llvm::detail::ExpectedHolder<T> Result;
      26          81 :   auto &EH = static_cast<llvm::detail::ErrorHolder &>(Result);
      27         324 :   EH = TakeError(Exp.takeError());
      28          81 :   if (Result.Success)
      29          80 :     Result.Value = &(*Exp);
      30          81 :   return Result;
      31             : }
      32             : 
      33             : template <typename T> ExpectedHolder<T> TakeExpected(Expected<T> &&Exp) {
      34          24 :   return TakeExpected(Exp);
      35             : }
      36             : } // namespace detail
      37             : 
      38             : #define EXPECT_THAT_ERROR(Err, Matcher)                                        \
      39             :   EXPECT_THAT(llvm::detail::TakeError(Err), Matcher)
      40             : #define ASSERT_THAT_ERROR(Err, Matcher)                                        \
      41             :   ASSERT_THAT(llvm::detail::TakeError(Err), Matcher)
      42             : 
      43             : #define EXPECT_THAT_EXPECTED(Err, Matcher)                                     \
      44             :   EXPECT_THAT(llvm::detail::TakeExpected(Err), Matcher)
      45             : #define ASSERT_THAT_EXPECTED(Err, Matcher)                                     \
      46             :   ASSERT_THAT(llvm::detail::TakeExpected(Err), Matcher)
      47             : 
      48        5400 : MATCHER(Succeeded, "") { return arg.Success; }
      49         396 : MATCHER(Failed, "") { return !arg.Success; }
      50             : 
      51          41 : MATCHER_P(HasValue, value,
      52             :           "succeeded with value " + testing::PrintToString(value)) {
      53           6 :   if (!arg.Success) {
      54             :     *result_listener << "operation failed";
      55             :     return false;
      56             :   }
      57             : 
      58             :   assert(arg.Value.hasValue());
      59          15 :   if (**arg.Value != value) {
      60           0 :     *result_listener << "but \"" + testing::PrintToString(**arg.Value) +
      61             :                             "\" != " + testing::PrintToString(value);
      62           0 :     return false;
      63             :   }
      64             : 
      65             :   return true;
      66             : }
      67             : } // namespace llvm
      68             : 
      69             : #endif

Generated by: LCOV version 1.13