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  bool Success;
21  std::string Message;
22 };
23 
24 template <typename T> struct ExpectedHolder : public ErrorHolder {
26  : ErrorHolder(std::move(Err)), Exp(Exp) {}
27 
29 };
30 
31 inline void PrintTo(const ErrorHolder &Err, std::ostream *Out) {
32  *Out << (Err.Success ? "succeeded" : "failed");
33  if (!Err.Success) {
34  *Out << " (" << StringRef(Err.Message).trim().str() << ")";
35  }
36 }
37 
38 template <typename T>
39 void PrintTo(const ExpectedHolder<T> &Item, std::ostream *Out) {
40  if (Item.Success) {
41  *Out << "succeeded with value " << ::testing::PrintToString(*Item.Exp);
42  } else {
43  PrintTo(static_cast<const ErrorHolder &>(Item), Out);
44  }
45 }
46 } // namespace detail
47 } // namespace llvm
48 
49 #endif
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:228
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
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)
LLVM_NODISCARD StringRef trim(char Char) const
Return string with consecutive Char characters starting from the left and right removed.
Definition: StringRef.h:836
ExpectedHolder(ErrorHolder Err, Expected< T > &Exp)
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49