1 //===- Testing/Support/SupportHelpers.h -----------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_TESTING_SUPPORT_SUPPORTHELPERS_H
11 #define LLVM_TESTING_SUPPORT_SUPPORTHELPERS_H
13 #include "llvm/ADT/SmallString.h"
14 #include "llvm/Support/Error.h"
15 #include "llvm/Support/raw_os_ostream.h"
16 #include "gtest/gtest-printers.h"
23 std::vector<std::shared_ptr<ErrorInfoBase>> Infos;
25 bool Success() const { return Infos.empty(); }
28 template <typename T> struct ExpectedHolder : public ErrorHolder {
29 ExpectedHolder(ErrorHolder Err, Expected<T> &Exp)
30 : ErrorHolder(std::move(Err)), Exp(Exp) {}
35 inline void PrintTo(const ErrorHolder &Err, std::ostream *Out) {
36 raw_os_ostream OS(*Out);
37 OS << (Err.Success() ? "succeeded" : "failed");
39 const char *Delim = " (";
40 for (const auto &Info : Err.Infos) {
50 void PrintTo(const ExpectedHolder<T> &Item, std::ostream *Out) {
52 *Out << "succeeded with value " << ::testing::PrintToString(*Item.Exp);
54 PrintTo(static_cast<const ErrorHolder &>(Item), Out);
60 SmallString<128> getInputFileDirectory(const char *Argv0);