Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / unittests / Expression / ClangParserTest.cpp
blobed5ee323b7d20d669d21daec48a7b7b9bfbcd7bc
1 //===-- ClangParserTest.cpp -----------------------------------------------===//
2 //
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
6 //
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;
25 namespace {
26 struct ClangHostTest : public testing::Test {
27 SubsystemRAII<FileSystem, HostInfo> subsystems;
29 } // namespace
31 static std::string ComputeClangResourceDir(std::string lldb_shlib_path,
32 bool verify = false) {
33 FileSpec clang_dir;
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) {
40 #if !defined(_WIN32)
41 std::string path_to_liblldb = "/foo/bar/lib/";
42 #else
43 std::string path_to_liblldb = "C:\\foo\\bar\\lib\\";
44 #endif
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());
60 std::string build =
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)));
93 #endif // __APPLE__