1 //===- TestUtilities.h ------------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLDB_UNITTESTS_UTILITY_HELPERS_TESTUTILITIES_H 10 #define LLDB_UNITTESTS_UTILITY_HELPERS_TESTUTILITIES_H 11 12 #include "llvm/ADT/SmallString.h" 13 #include "llvm/ADT/Twine.h" 14 #include "llvm/Support/Error.h" 15 #include "llvm/Support/FileUtilities.h" 16 #include <string> 17 18 #define ASSERT_NO_ERROR(x) \ 19 if (std::error_code ASSERT_NO_ERROR_ec = x) { \ 20 llvm::SmallString<128> MessageStorage; \ 21 llvm::raw_svector_ostream Message(MessageStorage); \ 22 Message << #x ": did not return errc::success.\n" \ 23 << "error number: " << ASSERT_NO_ERROR_ec.value() << "\n" \ 24 << "error message: " << ASSERT_NO_ERROR_ec.message() << "\n"; \ 25 GTEST_FATAL_FAILURE_(MessageStorage.c_str()); \ 26 } else { \ 27 } 28 29 namespace lldb_private { 30 std::string GetInputFilePath(const llvm::Twine &name); 31 32 class TestFile { 33 public: 34 static llvm::Expected<TestFile> fromYaml(llvm::StringRef Yaml); 35 static llvm::Expected<TestFile> fromYamlFile(const llvm::Twine &Name); 36 37 TestFile(TestFile &&RHS) : Name(std::move(RHS.Name)) { 38 RHS.Name = llvm::None; 39 } 40 41 ~TestFile(); 42 43 llvm::StringRef name() { return *Name; } 44 45 private: 46 TestFile(llvm::StringRef Name, llvm::FileRemover &&Remover) 47 : Name(std::string(Name)) { 48 Remover.releaseFile(); 49 } 50 void operator=(const TestFile &) = delete; 51 52 llvm::Optional<std::string> Name; 53 }; 54 } 55 56 #endif 57