LLVM  8.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/SmallString.h"
14 #include "llvm/Support/Error.h"
16 #include "gtest/gtest-printers.h"
17 
18 #include <string>
19 
20 namespace llvm {
21 namespace detail {
22 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 {
30  : ErrorHolder(std::move(Err)), Exp(Exp) {}
31 
33 };
34 
35 inline void PrintTo(const ErrorHolder &Err, std::ostream *Out) {
36  raw_os_ostream OS(*Out);
37  OS << (Err.Success() ? "succeeded" : "failed");
38  if (!Err.Success()) {
39  const char *Delim = " (";
40  for (const auto &Info : Err.Infos) {
41  OS << Delim;
42  Delim = "; ";
43  Info->log(OS);
44  }
45  OS << ")";
46  }
47 }
48 
49 template <typename T>
50 void PrintTo(const ExpectedHolder<T> &Item, std::ostream *Out) {
51  if (Item.Success()) {
52  *Out << "succeeded with value " << ::testing::PrintToString(*Item.Exp);
53  } else {
54  PrintTo(static_cast<const ErrorHolder &>(Item), Out);
55  }
56 }
57 } // namespace detail
58 
59 namespace unittest {
60 SmallString<128> getInputFileDirectory(const char *Argv0);
61 }
62 } // namespace llvm
63 
64 #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:938
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
SmallString< 128 > getInputFileDirectory(const char *Argv0)
ExpectedHolder(ErrorHolder Err, Expected< T > &Exp)