1 //===-- ClangParserTest.cpp -----------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "clang/Basic/Version.h"
10 #include "clang/Config/config.h"
11 #include "clang/Driver/Driver.h"
13 #include "Plugins/ExpressionParser/Clang/ClangHost.h"
14 #include "TestingSupport/SubsystemRAII.h"
15 #include "TestingSupport/TestUtilities.h"
16 #include "lldb/Host/Config.h"
17 #include "lldb/Host/FileSystem.h"
18 #include "lldb/Host/HostInfo.h"
19 #include "lldb/Utility/FileSpec.h"
20 #include "lldb/lldb-defines.h"
21 #include "gtest/gtest.h"
23 using namespace lldb_private
;
26 struct ClangHostTest
: public testing::Test
{
27 SubsystemRAII
<FileSystem
, HostInfo
> subsystems
;
31 static std::string
ComputeClangResourceDir(std::string lldb_shlib_path
,
32 bool verify
= false) {
34 FileSpec
lldb_shlib_spec(lldb_shlib_path
);
35 ComputeClangResourceDirectory(lldb_shlib_spec
, clang_dir
, verify
);
36 return clang_dir
.GetPath();
39 TEST_F(ClangHostTest
, ComputeClangResourceDirectory
) {
41 std::string path_to_liblldb
= "/foo/bar/lib/";
43 std::string path_to_liblldb
= "C:\\foo\\bar\\lib\\";
45 std::string path_to_clang_dir
= clang::driver::Driver::GetResourcesPath(
46 path_to_liblldb
+ "liblldb", CLANG_RESOURCE_DIR
);
47 EXPECT_EQ(ComputeClangResourceDir(path_to_liblldb
), path_to_clang_dir
);
49 // The path doesn't really exist, so setting verify to true should make
50 // ComputeClangResourceDir not give you path_to_clang_dir.
51 EXPECT_NE(ComputeClangResourceDir(path_to_liblldb
, true), path_to_clang_dir
);
54 #if defined(__APPLE__)
55 TEST_F(ClangHostTest
, MacOSX
) {
56 // This returns whatever the POSIX fallback returns.
57 std::string posix
= "/usr/lib/liblldb.dylib";
58 EXPECT_FALSE(ComputeClangResourceDir(posix
).empty());
61 "/lldb-macosx-x86_64/Library/Frameworks/LLDB.framework/Versions/A";
62 std::string build_clang
=
63 "/lldb-macosx-x86_64/Library/Frameworks/LLDB.framework/Resources/Clang";
64 EXPECT_EQ(ComputeClangResourceDir(build
), build_clang
);
66 std::string xcode
= "/Applications/Xcode.app/Contents/SharedFrameworks/"
67 "LLDB.framework/Versions/A";
68 std::string xcode_clang
=
69 "/Applications/Xcode.app/Contents/Developer/Toolchains/"
70 "XcodeDefault.xctoolchain/usr/lib/swift/clang";
71 EXPECT_EQ(ComputeClangResourceDir(xcode
), xcode_clang
);
73 std::string toolchain
=
74 "/Applications/Xcode.app/Contents/Developer/Toolchains/"
75 "Swift-4.1-development-snapshot.xctoolchain/System/Library/"
76 "PrivateFrameworks/LLDB.framework";
77 std::string toolchain_clang
=
78 "/Applications/Xcode.app/Contents/Developer/Toolchains/"
79 "Swift-4.1-development-snapshot.xctoolchain/usr/lib/swift/clang";
80 EXPECT_EQ(ComputeClangResourceDir(toolchain
), toolchain_clang
);
82 std::string cltools
= "/Library/Developer/CommandLineTools/Library/"
83 "PrivateFrameworks/LLDB.framework";
84 std::string cltools_clang
=
85 "/Library/Developer/CommandLineTools/Library/PrivateFrameworks/"
86 "LLDB.framework/Resources/Clang";
87 EXPECT_EQ(ComputeClangResourceDir(cltools
), cltools_clang
);
89 // Test that a bogus path is detected.
90 EXPECT_NE(ComputeClangResourceDir(GetInputFilePath(xcode
), true),
91 ComputeClangResourceDir(GetInputFilePath(xcode
)));