LCOV - code coverage report
Current view: top level - include/llvm/Testing/Support - SupportHelpers.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 16 16 100.0 %
Date: 2018-06-17 00:07:59 Functions: 12 14 85.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- Testing/Support/SupportHelpers.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_SUPPORTHELPERS_H
      11             : #define LLVM_TESTING_SUPPORT_SUPPORTHELPERS_H
      12             : 
      13             : #include "llvm/ADT/StringRef.h"
      14             : #include "llvm/Support/Error.h"
      15             : #include "gtest/gtest-printers.h"
      16             : 
      17             : namespace llvm {
      18             : namespace detail {
      19        1207 : struct ErrorHolder {
      20             :   std::vector<std::shared_ptr<ErrorInfoBase>> Infos;
      21             : 
      22             :   bool Success() const { return Infos.empty(); }
      23             : };
      24             : 
      25             : template <typename T> struct ExpectedHolder : public ErrorHolder {
      26             :   ExpectedHolder(ErrorHolder Err, Expected<T> &Exp)
      27         106 :       : ErrorHolder(std::move(Err)), Exp(Exp) {}
      28             : 
      29             :   Expected<T> &Exp;
      30             : };
      31             : 
      32        1001 : inline void PrintTo(const ErrorHolder &Err, std::ostream *Out) {
      33        1001 :   raw_os_ostream OS(*Out);
      34        1001 :   OS << (Err.Success() ? "succeeded" : "failed");
      35        1001 :   if (!Err.Success()) {
      36             :     const char *Delim = "  (";
      37         167 :     for (const auto &Info : Err.Infos) {
      38          84 :       OS << Delim;
      39             :       Delim = "; ";
      40          84 :       Info->log(OS);
      41             :     }
      42          83 :     OS << ")";
      43             :   }
      44        1001 : }
      45             : 
      46             : template <typename T>
      47         106 : void PrintTo(const ExpectedHolder<T> &Item, std::ostream *Out) {
      48         106 :   if (Item.Success()) {
      49         300 :     *Out << "succeeded with value " << ::testing::PrintToString(*Item.Exp);
      50             :   } else {
      51           6 :     PrintTo(static_cast<const ErrorHolder &>(Item), Out);
      52             :   }
      53         106 : }
      54             : } // namespace detail
      55             : } // namespace llvm
      56             : 
      57             : #endif

Generated by: LCOV version 1.13