1 //===-- ClangParserTest.cpp --------------------------------------*- C++-*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "Plugins/ExpressionParser/Clang/ClangHost.h"
11 #include "TestingSupport/TestUtilities.h"
12 #include "lldb/Host/FileSystem.h"
13 #include "lldb/Host/HostInfo.h"
14 #include "lldb/Utility/FileSpec.h"
15 #include "lldb/lldb-defines.h"
16 #include "gtest/gtest.h"
17 
18 using namespace lldb_private;
19 
20 namespace {
21 struct ClangHostTest : public testing::Test {
22   static void SetUpTestCase() {
23     FileSystem::Initialize();
24     HostInfo::Initialize();
25   }
26   static void TearDownTestCase() {
27     HostInfo::Terminate();
28     FileSystem::Terminate();
29   }
30 };
31 } // namespace
32 
33 #ifdef __APPLE__
34 static std::string ComputeClangDir(std::string lldb_shlib_path,
35                                    bool verify = false) {
36   FileSpec clang_dir;
37   FileSpec lldb_shlib_spec(lldb_shlib_path);
38   ComputeClangDirectory(lldb_shlib_spec, clang_dir, verify);
39   return clang_dir.GetPath();
40 }
41 
42 TEST_F(ClangHostTest, MacOSX) {
43   // This returns whatever the POSIX fallback returns.
44   std::string posix = "/usr/lib/liblldb.dylib";
45   EXPECT_FALSE(ComputeClangDir(posix).empty());
46 
47   std::string build =
48       "/lldb-macosx-x86_64/Library/Frameworks/LLDB.framework/Versions/A";
49   std::string build_clang =
50       "/lldb-macosx-x86_64/Library/Frameworks/LLDB.framework/Resources/Clang";
51   EXPECT_EQ(ComputeClangDir(build), build_clang);
52 
53   std::string xcode = "/Applications/Xcode.app/Contents/SharedFrameworks/"
54                       "LLDB.framework/Versions/A";
55   std::string xcode_clang =
56       "/Applications/Xcode.app/Contents/Developer/Toolchains/"
57       "XcodeDefault.xctoolchain/usr/lib/swift/clang";
58   EXPECT_EQ(ComputeClangDir(xcode), xcode_clang);
59 
60   std::string toolchain =
61       "/Applications/Xcode.app/Contents/Developer/Toolchains/"
62       "Swift-4.1-development-snapshot.xctoolchain/System/Library/"
63       "PrivateFrameworks/LLDB.framework";
64   std::string toolchain_clang =
65       "/Applications/Xcode.app/Contents/Developer/Toolchains/"
66       "Swift-4.1-development-snapshot.xctoolchain/usr/lib/swift/clang";
67   EXPECT_EQ(ComputeClangDir(toolchain), toolchain_clang);
68 
69   std::string cltools = "/Library/Developer/CommandLineTools/Library/"
70                         "PrivateFrameworks/LLDB.framework";
71   std::string cltools_clang =
72       "/Library/Developer/CommandLineTools/Library/PrivateFrameworks/"
73       "LLDB.framework/Resources/Clang";
74   EXPECT_EQ(ComputeClangDir(cltools), cltools_clang);
75 
76   // Test that a bogus path is detected.
77   EXPECT_NE(ComputeClangDir(GetInputFilePath(xcode), true),
78             ComputeClangDir(GetInputFilePath(xcode)));
79 }
80 #endif
81