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