LLVM  7.0.0svn
SupportHelpers.h
Go to the documentation of this file.
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 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 {
27  : ErrorHolder(std::move(Err)), Exp(Exp) {}
28 
30 };
31 
32 inline void PrintTo(const ErrorHolder &Err, std::ostream *Out) {
33  raw_os_ostream OS(*Out);
34  OS << (Err.Success() ? "succeeded" : "failed");
35  if (!Err.Success()) {
36  const char *Delim = " (";
37  for (const auto &Info : Err.Infos) {
38  OS << Delim;
39  Delim = "; ";
40  Info->log(OS);
41  }
42  OS << ")";
43  }
44 }
45 
46 template <typename T>
47 void PrintTo(const ExpectedHolder<T> &Item, std::ostream *Out) {
48  if (Item.Success()) {
49  *Out << "succeeded with value " << ::testing::PrintToString(*Item.Exp);
50  } else {
51  PrintTo(static_cast<const ErrorHolder &>(Item), Out);
52  }
53 }
54 } // namespace detail
55 } // namespace llvm
56 
57 #endif
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
raw_os_ostream - A raw_ostream that writes to an std::ostream.
Definition: BitVector.h:921
Tagged union holding either a T or a Error.
Definition: CachePruning.h:23
void PrintTo(const ErrorHolder &Err, std::ostream *Out)
std::vector< std::shared_ptr< ErrorInfoBase > > Infos
ExpectedHolder(ErrorHolder Err, Expected< T > &Exp)