blob: 13ff07c2e135a8b064cec451b2abdc0f93a925e3 [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
Fangrui Song95dd7a22018-09-06 19:51:20 +000016SmallString<128> llvm::unittest::getInputFileDirectory(const char *Argv0) {
17 llvm::SmallString<128> Result = llvm::sys::path::parent_path(Argv0);
Zachary Turnere9f1df82018-09-05 23:30:17 +000018 llvm::sys::fs::make_absolute(Result);
19 llvm::sys::path::append(Result, "llvm.srcdir.txt");
20
Zachary Turner9ec23042018-09-05 23:45:48 +000021 EXPECT_TRUE(llvm::sys::fs::is_regular_file(Result))
Zachary Turnere9f1df82018-09-05 23:30:17 +000022 << "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);
Zachary Turner5cda1b82018-09-06 00:06:20 +000033 return Result;
Zachary Turnere9f1df82018-09-05 23:30:17 +000034}