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-10-20 13:21:21 Functions: 8 10 80.0 %
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        1129 : 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         102 :       : ErrorHolder(std::move(Err)), Exp(Exp) {}
      31             : 
      32             :   Expected<T> &Exp;
      33             : };
      34             : 
      35        1033 : inline void PrintTo(const ErrorHolder &Err, std::ostream *Out) {
      36        1033 :   raw_os_ostream OS(*Out);
      37        1146 :   OS << (Err.Success() ? "succeeded" : "failed");
      38        1033 :   if (!Err.Success()) {
      39             :     const char *Delim = "  (";
      40         227 :     for (const auto &Info : Err.Infos) {
      41         114 :       OS << Delim;
      42             :       Delim = "; ";
      43         114 :       Info->log(OS);
      44             :     }
      45         113 :     OS << ")";
      46             :   }
      47        1033 : }
      48             : 
      49             : template <typename T>
      50         102 : void PrintTo(const ExpectedHolder<T> &Item, std::ostream *Out) {
      51         102 :   if (Item.Success()) {
      52         288 :     *Out << "succeeded with value " << ::testing::PrintToString(*Item.Exp);
      53             :   } else {
      54           6 :     PrintTo(static_cast<const ErrorHolder &>(Item), Out);
      55             :   }
      56         102 : }
      57          17 : } // namespace detail
      58          17 : 
      59          48 : namespace unittest {
      60             : SmallString<128> getInputFileDirectory(const char *Argv0);
      61           1 : }
      62             : } // namespace llvm
      63          17 : 
      64          35 : #endif

Generated by: LCOV version 1.13