SupportHelpers.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #include "llvm/Testing/Support/SupportHelpers.h"
  2. #include "llvm/ADT/SmallString.h"
  3. #include "llvm/ADT/Twine.h"
  4. #include "llvm/Support/Error.h"
  5. #include "llvm/Support/FileSystem.h"
  6. #include "llvm/Support/MemoryBuffer.h"
  7. #include "llvm/Support/Path.h"
  8. #include "gtest/gtest.h"
  9. using namespace llvm;
  10. using namespace llvm::unittest;
  11. extern const char *TestMainArgv0;
  12. SmallString<128> llvm::unittest::getInputFileDirectory() {
  13. llvm::SmallString<128> Result = llvm::sys::path::parent_path(TestMainArgv0);
  14. llvm::sys::fs::make_absolute(Result);
  15. llvm::sys::path::append(Result, "llvm.srcdir.txt");
  16. EXPECT_TRUE(llvm::sys::fs::is_directory(Result))
  17. << "Unit test source directory file does not exist.";
  18. auto File = MemoryBuffer::getFile(Result);
  19. EXPECT_TRUE(static_cast<bool>(File))
  20. << "Could not open unit test source directory file.";
  21. Result.clear();
  22. Result.append((*File)->getBuffer().trim());
  23. llvm::sys::path::append(Result, "Inputs");
  24. llvm::sys::path::native(Result);
  25. return std::move(Result);
  26. }