From c02670ed50f009eeb24ad7f0fe00cbf887e008d0 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Wed, 18 Nov 2015 16:14:27 +0000 Subject: [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 llvm-svn: 253466 --- clang/unittests/libclang/LibclangTest.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'clang/unittests/libclang/LibclangTest.cpp') diff --git a/clang/unittests/libclang/LibclangTest.cpp b/clang/unittests/libclang/LibclangTest.cpp index becebf0..fc28b17 100644 --- a/clang/unittests/libclang/LibclangTest.cpp +++ b/clang/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 \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(); +} -- cgit v1.1