1 //===-- PlatformDarwinTest.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 //===----------------------------------------------------------------------===// 8 9 #include "gtest/gtest.h" 10 11 #include "Plugins/Platform/MacOSX/PlatformDarwin.h" 12 13 #include "llvm/ADT/StringRef.h" 14 15 #include <tuple> 16 17 using namespace lldb; 18 using namespace lldb_private; 19 20 struct PlatformDarwinTester : public PlatformDarwin { 21 public: 22 using PlatformDarwin::FindComponentInPath; 23 using PlatformDarwin::FindXcodeContentsDirectoryInPath; 24 }; 25 26 TEST(PlatformDarwinTest, TestParseVersionBuildDir) { 27 llvm::VersionTuple V; 28 llvm::StringRef D; 29 30 std::tie(V, D) = PlatformDarwin::ParseVersionBuildDir("1.2.3 (test1)"); 31 EXPECT_EQ(llvm::VersionTuple(1, 2, 3), V); 32 EXPECT_EQ("test1", D); 33 34 std::tie(V, D) = PlatformDarwin::ParseVersionBuildDir("2.3 (test2)"); 35 EXPECT_EQ(llvm::VersionTuple(2, 3), V); 36 EXPECT_EQ("test2", D); 37 38 std::tie(V, D) = PlatformDarwin::ParseVersionBuildDir("3 (test3)"); 39 EXPECT_EQ(llvm::VersionTuple(3), V); 40 EXPECT_EQ("test3", D); 41 42 std::tie(V, D) = PlatformDarwin::ParseVersionBuildDir("1.2.3 (test"); 43 EXPECT_EQ(llvm::VersionTuple(1, 2, 3), V); 44 EXPECT_EQ("test", D); 45 46 std::tie(V, D) = PlatformDarwin::ParseVersionBuildDir("2.3.4 test"); 47 EXPECT_EQ(llvm::VersionTuple(2, 3, 4), V); 48 EXPECT_EQ("", D); 49 50 std::tie(V, D) = PlatformDarwin::ParseVersionBuildDir("3.4.5"); 51 EXPECT_EQ(llvm::VersionTuple(3, 4, 5), V); 52 } 53 54 TEST(PlatformDarwinTest, FindXcodeContentsDirectoryInPath) { 55 std::string standard = 56 "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/" 57 "Developer/SDKs/MacOSX.sdk"; 58 EXPECT_EQ("/Applications/Xcode.app/Contents", 59 PlatformDarwinTester::FindXcodeContentsDirectoryInPath(standard)); 60 61 std::string standard_version = 62 "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/" 63 "Developer/SDKs/MacOSX10.15.sdk"; 64 EXPECT_EQ( 65 "/Applications/Xcode.app/Contents", 66 PlatformDarwinTester::FindXcodeContentsDirectoryInPath(standard_version)); 67 68 std::string beta = "/Applications/Xcode-beta.app/Contents/Developer/" 69 "Platforms/MacOSX.platform/" 70 "Developer/SDKs/MacOSX10.15.sdk"; 71 EXPECT_EQ("/Applications/Xcode-beta.app/Contents", 72 PlatformDarwinTester::FindXcodeContentsDirectoryInPath(beta)); 73 74 std::string no_app = 75 "/Applications/Xcode/Contents/Developer/Platforms/MacOSX.platform/" 76 "Developer/SDKs/MacOSX10.15.sdk"; 77 EXPECT_EQ("", PlatformDarwinTester::FindXcodeContentsDirectoryInPath(no_app)); 78 79 std::string no_contents = 80 "/Applications/Xcode.app/Developer/Platforms/MacOSX.platform/" 81 "Developer/SDKs/MacOSX10.15.sdk"; 82 EXPECT_EQ( 83 "", PlatformDarwinTester::FindXcodeContentsDirectoryInPath(no_contents)); 84 85 std::string no_capitalization = 86 "/Applications/Xcode.app/contents/Developer/Platforms/MacOSX.platform/" 87 "Developer/SDKs/MacOSX10.15.sdk"; 88 EXPECT_EQ("", PlatformDarwinTester::FindXcodeContentsDirectoryInPath( 89 no_capitalization)); 90 } 91 92 TEST(PlatformDarwinTest, FindComponentInPath) { 93 EXPECT_EQ("/path/to/foo", 94 PlatformDarwinTester::FindComponentInPath("/path/to/foo/", "foo")); 95 96 EXPECT_EQ("/path/to/foo", 97 PlatformDarwinTester::FindComponentInPath("/path/to/foo", "foo")); 98 99 EXPECT_EQ("/path/to/foobar", PlatformDarwinTester::FindComponentInPath( 100 "/path/to/foobar", "foo")); 101 102 EXPECT_EQ("/path/to/foobar", PlatformDarwinTester::FindComponentInPath( 103 "/path/to/foobar", "bar")); 104 105 EXPECT_EQ("", 106 PlatformDarwinTester::FindComponentInPath("/path/to/foo", "bar")); 107 } 108