blob: c0f4f44e1441102018f9276441a2703d19e70cdd [file] [log] [blame]
Zachary Turnere9f1df82018-09-05 23:30:17 +00001
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
13using namespace llvm;
14using namespace llvm::unittest;
15
16extern const char *TestMainArgv0;
17
18SmallString<128> llvm::unittest::getInputFileDirectory() {
19 llvm::SmallString<128> Result = llvm::sys::path::parent_path(TestMainArgv0);
20 llvm::sys::fs::make_absolute(Result);
21 llvm::sys::path::append(Result, "llvm.srcdir.txt");
22
Zachary Turner9ec23042018-09-05 23:45:48 +000023 EXPECT_TRUE(llvm::sys::fs::is_regular_file(Result))
Zachary Turnere9f1df82018-09-05 23:30:17 +000024 << "Unit test source directory file does not exist.";
25
26 auto File = MemoryBuffer::getFile(Result);
27
28 EXPECT_TRUE(static_cast<bool>(File))
29 << "Could not open unit test source directory file.";
30
31 Result.clear();
32 Result.append((*File)->getBuffer().trim());
33 llvm::sys::path::append(Result, "Inputs");
34 llvm::sys::path::native(Result);
Zachary Turner5cda1b82018-09-06 00:06:20 +000035 return Result;
Zachary Turnere9f1df82018-09-05 23:30:17 +000036}