-
-
Notifications
You must be signed in to change notification settings - Fork 508
/
XCFrameworkBuilderIntegrationTests.swift
149 lines (129 loc) · 6.16 KB
/
XCFrameworkBuilderIntegrationTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import Basic
import Foundation
import SPMUtility
import TuistCore
import TuistSupport
import XCTest
@testable import TuistCoreTesting
@testable import TuistKit
@testable import TuistSupportTesting
final class XCFrameworkBuilderIntegrationTests: TuistTestCase {
var subject: XCFrameworkBuilder!
var plistDecoder: PropertyListDecoder!
override func setUp() {
super.setUp()
plistDecoder = PropertyListDecoder()
subject = XCFrameworkBuilder(printOutput: false)
}
override func tearDown() {
subject = nil
plistDecoder = nil
super.tearDown()
}
func test_build_when_iOS_framework() throws {
// Given
let frameworksPath = temporaryFixture("Frameworks")
let projectPath = frameworksPath.appending(component: "Frameworks.xcodeproj")
let target = Target.test(name: "iOS", platform: .iOS, product: .framework, productName: "iOS")
// When
let xcframeworkPath = try subject.build(projectPath: projectPath, target: target)
let infoPlist = try self.infoPlist(xcframeworkPath: xcframeworkPath)
// Then
XCTAssertTrue(FileHandler.shared.exists(xcframeworkPath))
XCTAssertNotNil(infoPlist.availableLibraries.first(where: { $0.supportedArchitectures.contains("arm64") }))
XCTAssertNotNil(infoPlist.availableLibraries.first(where: { $0.supportedArchitectures.contains("x86_64") }))
XCTAssertTrue(infoPlist.availableLibraries.allSatisfy { $0.supportedPlatform == "ios" })
XCTAssertPrinterOutputContains("""
Building .xcframework for iOS
Building iOS for device
Building iOS for simulator
Exporting xcframework for iOS
""")
try FileHandler.shared.delete(xcframeworkPath)
}
func test_build_when_macOS_framework() throws {
// Given
let frameworksPath = temporaryFixture("Frameworks")
let projectPath = frameworksPath.appending(component: "Frameworks.xcodeproj")
let target = Target.test(name: "macOS", platform: .macOS, product: .framework, productName: "macOS")
// When
let xcframeworkPath = try subject.build(projectPath: projectPath, target: target)
let infoPlist = try self.infoPlist(xcframeworkPath: xcframeworkPath)
// Then
XCTAssertTrue(FileHandler.shared.exists(xcframeworkPath))
XCTAssertNotNil(infoPlist.availableLibraries.first(where: { $0.supportedArchitectures.contains("x86_64") }))
XCTAssertTrue(infoPlist.availableLibraries.allSatisfy { $0.supportedPlatform == "macos" })
XCTAssertPrinterOutputContains("""
Building .xcframework for macOS
Building macOS for device
Exporting xcframework for macOS
""")
try FileHandler.shared.delete(xcframeworkPath)
}
func test_build_when_tvOS_framework() throws {
// Given
let frameworksPath = temporaryFixture("Frameworks")
let projectPath = frameworksPath.appending(component: "Frameworks.xcodeproj")
let target = Target.test(name: "tvOS", platform: .tvOS, product: .framework, productName: "tvOS")
// When
let xcframeworkPath = try subject.build(projectPath: projectPath, target: target)
let infoPlist = try self.infoPlist(xcframeworkPath: xcframeworkPath)
// Then
XCTAssertTrue(FileHandler.shared.exists(xcframeworkPath))
XCTAssertNotNil(infoPlist.availableLibraries.first(where: { $0.supportedArchitectures.contains("x86_64") }))
XCTAssertNotNil(infoPlist.availableLibraries.first(where: { $0.supportedArchitectures.contains("arm64") }))
XCTAssertTrue(infoPlist.availableLibraries.allSatisfy { $0.supportedPlatform == "tvos" })
XCTAssertPrinterOutputContains("""
Building .xcframework for tvOS
Building tvOS for device
Building tvOS for simulator
Exporting xcframework for tvOS
""")
try FileHandler.shared.delete(xcframeworkPath)
}
func test_build_when_watchOS_framework() throws {
// Given
let frameworksPath = temporaryFixture("Frameworks")
let projectPath = frameworksPath.appending(component: "Frameworks.xcodeproj")
let target = Target.test(name: "watchOS", platform: .watchOS, product: .framework, productName: "watchOS")
// When
let xcframeworkPath = try subject.build(projectPath: projectPath, target: target)
let infoPlist = try self.infoPlist(xcframeworkPath: xcframeworkPath)
// Then
XCTAssertTrue(FileHandler.shared.exists(xcframeworkPath))
XCTAssertNotNil(infoPlist.availableLibraries.first(where: { $0.supportedArchitectures.contains("i386") }))
XCTAssertNotNil(infoPlist.availableLibraries.first(where: { $0.supportedArchitectures.contains("armv7k") }))
XCTAssertNotNil(infoPlist.availableLibraries.first(where: { $0.supportedArchitectures.contains("arm64_32") }))
XCTAssertTrue(infoPlist.availableLibraries.allSatisfy { $0.supportedPlatform == "watchos" })
XCTAssertPrinterOutputContains("""
Building .xcframework for watchOS
Building watchOS for device
Building watchOS for simulator
Exporting xcframework for watchOS
""")
try FileHandler.shared.delete(xcframeworkPath)
}
fileprivate func infoPlist(xcframeworkPath: AbsolutePath) throws -> XCFrameworkInfoPlist {
let infoPlistPath = xcframeworkPath.appending(component: "Info.plist")
let data = try Data(contentsOf: infoPlistPath.url)
return try plistDecoder.decode(XCFrameworkInfoPlist.self, from: data)
}
}
private struct XCFrameworkInfoPlist: Decodable {
let availableLibraries: [Library]
enum CodingKeys: String, CodingKey {
case availableLibraries = "AvailableLibraries"
}
fileprivate struct Library: Decodable {
let identifier: String
let path: String
let supportedArchitectures: [String]
let supportedPlatform: String
enum CodingKeys: String, CodingKey {
case identifier = "LibraryIdentifier"
case path = "LibraryPath"
case supportedArchitectures = "SupportedArchitectures"
case supportedPlatform = "SupportedPlatform"
}
}
}