summaryrefslogtreecommitdiffstats
path: root/unittests/libclang
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2015-11-18 16:14:27 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2015-11-18 16:14:27 +0000
commitb1dfd660998cc98c27541047a6f255808c232d62 (patch)
tree3b5989a86a26a44c538d3866940247cbe58f4180 /unittests/libclang
parent980d9c87b942f16521e39fd308bdc7f6aef78da2 (diff)
[libclang] Add entry points that take a full command line including argv[0].
This provides both a more uniform interface and makes libclang behave like clang tooling wrt relative paths against argv[0]. This is necessary for finding paths to a c++ standard library relative to a clang binary given in a compilation database. It can also be used to find paths relative to libclang.so if the full path to it is passed in. Differential Revision: http://reviews.llvm.org/D14695 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253466 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/libclang')
-rw-r--r--unittests/libclang/LibclangTest.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/unittests/libclang/LibclangTest.cpp b/unittests/libclang/LibclangTest.cpp
index becebf076d..fc28b172e6 100644
--- a/unittests/libclang/LibclangTest.cpp
+++ b/unittests/libclang/LibclangTest.cpp
@@ -379,8 +379,10 @@ public:
Filename = Path.str();
Files.insert(Filename);
}
+ llvm::sys::fs::create_directories(llvm::sys::path::parent_path(Filename));
std::ofstream OS(Filename);
OS << Contents;
+ assert(OS.good());
}
void DisplayDiagnostics() {
unsigned NumDiagnostics = clang_getNumDiagnostics(ClangTU);
@@ -465,3 +467,27 @@ TEST_F(LibclangReparseTest, ReparseWithModule) {
ASSERT_TRUE(ReparseTU(0, nullptr /* No unsaved files. */));
EXPECT_EQ(0U, clang_getNumDiagnostics(ClangTU));
}
+
+TEST_F(LibclangReparseTest, clang_parseTranslationUnit2FullArgv) {
+ std::string EmptyFiles[] = {"lib/gcc/arm-linux-gnueabi/4.6.1/crtbegin.o",
+ "include/arm-linux-gnueabi/.keep",
+ "include/c++/4.6.1/vector"};
+
+ for (auto &Name : EmptyFiles)
+ WriteFile(Name, "\n");
+
+ std::string Filename = "test.cc";
+ WriteFile(Filename, "#include <vector>\n");
+
+ std::string Clang = "bin/clang";
+ WriteFile(Clang, "");
+
+ const char *Argv[] = {Clang.c_str(), "-target", "arm-linux-gnueabi"};
+
+ EXPECT_EQ(CXError_Success,
+ clang_parseTranslationUnit2FullArgv(Index, Filename.c_str(), Argv,
+ sizeof(Argv) / sizeof(Argv[0]),
+ nullptr, 0, TUFlags, &ClangTU));
+ EXPECT_EQ(0U, clang_getNumDiagnostics(ClangTU));
+ DisplayDiagnostics();
+}