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 17namespace llvm { 18namespace detail { 19struct ErrorHolder { 20 bool Success; 21 std::string Message; 22}; 23 24template <typename T> struct ExpectedHolder : public ErrorHolder { 25 Optional<T *> Value; 26}; 27 28inline 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 35template <typename T> 36void 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 48