LLVM  6.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 };
27 
28 inline void PrintTo(const ErrorHolder &Err, std::ostream *Out) {
29  *Out << (Err.Success ? "succeeded" : "failed");
30  if (!Err.Success) {
31  *Out << " (" << StringRef(Err.Message).trim().str() << ")";
32  }
33 }
34 
35 template <typename T>
36 void PrintTo(const ExpectedHolder<T> &Item, std::ostream *Out) {
37  if (Item.Success) {
38  *Out << "succeeded with value \"" << ::testing::PrintToString(**Item.Value)
39  << "\"";
40  } else {
41  PrintTo(static_cast<const ErrorHolder &>(Item), Out);
42  }
43 }
44 } // namespace detail
45 } // namespace llvm
46 
47 #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
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
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49