LCOV - code coverage report
Current view: top level - include/llvm/Testing/Support - SupportHelpers.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 30 31 96.8 %
Date: 2018-09-23 13:06:45 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/SmallString.h"
      14             : #include "llvm/Support/Error.h"
      15             : #include "llvm/Support/raw_os_ostream.h"
      16             : #include "gtest/gtest-printers.h"
      17             : 
      18             : #include <string>
      19             : 
      20             : namespace llvm {
      21             : namespace detail {
      22        1121 : struct ErrorHolder {
      23             :   std::vector<std::shared_ptr<ErrorInfoBase>> Infos;
      24             : 
      25             :   bool Success() const { return Infos.empty(); }
      26             : };
      27             : 
      28             : template <typename T> struct ExpectedHolder : public ErrorHolder {
      29             :   ExpectedHolder(ErrorHolder Err, Expected<T> &Exp)
      30         108 :       : ErrorHolder(std::move(Err)), Exp(Exp) {}
      31             : 
      32             :   Expected<T> &Exp;
      33             : };
      34             : 
      35        1019 : inline void PrintTo(const ErrorHolder &Err, std::ostream *Out) {
      36        1019 :   raw_os_ostream OS(*Out);
      37        1109 :   OS << (Err.Success() ? "succeeded" : "failed");
      38        1019 :   if (!Err.Success()) {
      39             :     const char *Delim = "  (";
      40         181 :     for (const auto &Info : Err.Infos) {
      41          91 :       OS << Delim;
      42             :       Delim = "; ";
      43          91 :       Info->log(OS);
      44             :     }
      45          90 :     OS << ")";
      46             :   }
      47        1019 : }
      48             : 
      49             : template <typename T>
      50         108 : void PrintTo(const ExpectedHolder<T> &Item, std::ostream *Out) {
      51         108 :   if (Item.Success()) {
      52         306 :     *Out << "succeeded with value " << ::testing::PrintToString(*Item.Exp);
      53             :   } else {
      54           6 :     PrintTo(static_cast<const ErrorHolder &>(Item), Out);
      55             :   }
      56         108 : }
      57          19 : } // namespace detail
      58          19 : 
      59          54 : namespace unittest {
      60             : SmallString<128> getInputFileDirectory(const char *Argv0);
      61           1 : }
      62             : } // namespace llvm
      63          19 : 
      64          39 : #endif

Generated by: LCOV version 1.13