-
Notifications
You must be signed in to change notification settings - Fork 173
Expand file tree
/
Copy pathModels+FirstWithVersionTests.swift
More file actions
181 lines (152 loc) · 11.3 KB
/
Copy pathModels+FirstWithVersionTests.swift
File metadata and controls
181 lines (152 loc) · 11.3 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import Path
import XCTest
import Version
@testable import XcodesKit
final class ModelsFirstWithVersionTests: XCTestCase {
let xcodes = [
Xcode(version: Version(xcodeVersion: "1.2.3")!, url: URL(fileURLWithPath: "https://developer.apple.com/Xcode1.2.3.app"), filename: "Xcode1.2.3.app", releaseDate: nil),
Xcode(version: Version(xcodeVersion: "1.2.3 Beta 1")!, url: URL(fileURLWithPath: "https://developer.apple.com/Xcode1.2.3Beta1.app"), filename: "Xcode1.2.3Beta1.app", releaseDate: nil),
Xcode(version: Version(xcodeVersion: "1.2.3 Beta 2")!, url: URL(fileURLWithPath: "https://developer.apple.com/Xcode1.2.3Beta2.app"), filename: "Xcode1.2.3Beta2.app", releaseDate: nil),
Xcode(version: Version(xcodeVersion: "4.5.6 Beta 1")!, url: URL(fileURLWithPath: "https://developer.apple.com/Xcode4.5.6Beta1.app"), filename: "Xcode4.5.6Beta1app", releaseDate: nil),
Xcode(version: Version(xcodeVersion: "4.5.6 Beta 2")!, url: URL(fileURLWithPath: "https://developer.apple.com/Xcode4.5.6Beta2.app"), filename: "Xcode4.5.6Beta2.app", releaseDate: nil),
Xcode(version: Version("7.8.9-GM+ABC123")!, url: URL(fileURLWithPath: "https://developer.apple.com/Xcode7.8.9GM.app"), filename: "Xcode7.8.9GM.app", releaseDate: nil),
Xcode(version: Version("7.8.9+ABC123")!, url: URL(fileURLWithPath: "https://developer.apple.com/Xcode7.8.9.app"), filename: "Xcode7.8.9.app", releaseDate: nil),
Xcode(version: Version(xcodeVersion: "10.11.12 Release Candidate")!, url: URL(fileURLWithPath: "https://developer.apple.com/Xcode10.11.12ReleaseCandidate.app"), filename: "Xcode10.11.12ReleaseCandidate.app", releaseDate: nil),
Xcode(version: Version(11, 12, 13, prereleaseIdentifiers: ["Release", "Candidate"], buildMetadataIdentifiers: ["DEF456"]), url: URL(fileURLWithPath: "https://developer.apple.com/Xcode11.12.13ReleaseCandidate.app"), filename: "Xcode11.12.13ReleaseCandidate.app", releaseDate: nil),
]
let installedXcodes = [
InstalledXcode(path: Path("/Applications/Xcode-1.2.3.app")!, version: Version(xcodeVersion: "1.2.3")!),
InstalledXcode(path: Path("/Applications/Xcode-1.2.3-beta.1.app")!, version: Version(xcodeVersion: "1.2.3 Beta 1")!),
InstalledXcode(path: Path("/Applications/Xcode-1.2.3-beta.2.app")!, version: Version(xcodeVersion: "1.2.3 Beta 2")!),
InstalledXcode(path: Path("/Applications/Xcode-4.5.6-beta.1.app")!, version: Version(xcodeVersion: "4.5.6 Beta 1")!),
InstalledXcode(path: Path("/Applications/Xcode-4.5.6-beta.2.app")!, version: Version(xcodeVersion: "4.5.6 Beta 2")!),
InstalledXcode(path: Path("/Applications/Xcode-7.8.9-gm.app")!, version: Version("7.8.9-GM+ABC123")!),
InstalledXcode(path: Path("/Applications/Xcode-7.8.9.app")!, version: Version("7.8.9+ABC123")!),
InstalledXcode(path: Path("/Applications/Xcode-10.11.12-release.candidate.app")!, version: Version(xcodeVersion: "10.11.12 Release Candidate")!),
InstalledXcode(path: Path("/Applications/Xcode-11.12.13-release.candidate.app")!, version: Version(11, 12, 13, prereleaseIdentifiers: ["Release", "Candidate"], buildMetadataIdentifiers: ["DEF456"])),
]
func test_xcodes_exactMatch() {
XCTAssertEqual(
xcodes.first(withVersion: Version(xcodeVersion: "1.2.3")!),
Xcode(version: Version(xcodeVersion: "1.2.3")!, url: URL(fileURLWithPath: "https://developer.apple.com/Xcode1.2.3.app"), filename: "Xcode1.2.3.app", releaseDate: nil)
)
XCTAssertEqual(
xcodes.first(withVersion: Version(xcodeVersion: "1.2.3 Beta 2")!),
Xcode(version: Version(xcodeVersion: "1.2.3 Beta 2")!, url: URL(fileURLWithPath: "https://developer.apple.com/Xcode1.2.3Beta2.app"), filename: "Xcode1.2.3Beta2.app", releaseDate: nil)
)
// With build metadata
XCTAssertEqual(
xcodes.first(withVersion: Version(xcodeVersion: "7.8.9 gm")!),
Xcode(version: Version("7.8.9-GM+ABC123")!, url: URL(fileURLWithPath: "https://developer.apple.com/Xcode7.8.9GM.app"), filename: "Xcode7.8.9GM.app", releaseDate: nil)
)
XCTAssertEqual(
xcodes.first(withVersion: Version(xcodeVersion: "7.8.9")!),
Xcode(version: Version("7.8.9+ABC123")!, url: URL(fileURLWithPath: "https://developer.apple.com/Xcode7.8.9.app"), filename: "Xcode7.8.9.app", releaseDate: nil)
)
}
func test_xcodes_fuzzyMatch() {
XCTAssertEqual(
xcodes.first(withVersion: Version(xcodeVersion: "10.11.12")!),
Xcode(version: Version(xcodeVersion: "10.11.12 Release Candidate")!, url: URL(fileURLWithPath: "https://developer.apple.com/Xcode10.11.12ReleaseCandidate.app"), filename: "Xcode10.11.12ReleaseCandidate.app", releaseDate: nil)
)
// With build metadata
XCTAssertEqual(
xcodes.first(withVersion: Version(xcodeVersion: "11.12.13")!),
Xcode(version: Version(11, 12, 13, prereleaseIdentifiers: ["Release", "Candidate"], buildMetadataIdentifiers: ["DEF456"]), url: URL(fileURLWithPath: "https://developer.apple.com/Xcode11.12.13ReleaseCandidate.app"), filename: "Xcode11.12.13ReleaseCandidate.app", releaseDate: nil)
)
}
func test_xcodes_noMatch() {
XCTAssertEqual(
xcodes.first(withVersion: Version(xcodeVersion: "3.4.5")!),
nil
)
}
func test_xcodes_multipleMatches() {
XCTAssertEqual(
xcodes.first(withVersion: Version(xcodeVersion: "4.5.6")!),
nil
)
}
func test_installedXcodes_exactMatch() {
XCTAssertEqual(
installedXcodes.first(withVersion: Version(xcodeVersion: "1.2.3")!),
InstalledXcode(path: Path("/Applications/Xcode-1.2.3.app")!, version: Version(xcodeVersion: "1.2.3")!)
)
XCTAssertEqual(
installedXcodes.first(withVersion: Version(xcodeVersion: "1.2.3 Beta 2")!),
InstalledXcode(path: Path("/Applications/Xcode-1.2.3-beta.2.app")!, version: Version(xcodeVersion: "1.2.3 Beta 2")!)
)
XCTAssertEqual(
installedXcodes.first(withVersion: Version(xcodeVersion: "1.2.3b2")!),
InstalledXcode(path: Path("/Applications/Xcode-1.2.3-beta.2.app")!, version: Version(xcodeVersion: "1.2.3 Beta 2")!)
)
// With build metadata
XCTAssertEqual(
installedXcodes.first(withVersion: Version(xcodeVersion: "7.8.9 gm")!),
InstalledXcode(path: Path("/Applications/Xcode-7.8.9-gm.app")!, version: Version("7.8.9-GM+ABC123")!)
)
XCTAssertEqual(
installedXcodes.first(withVersion: Version(xcodeVersion: "7.8.9")!),
InstalledXcode(path: Path("/Applications/Xcode-7.8.9.app")!, version: Version("7.8.9+ABC123")!)
)
}
func test_installedXcodes_fuzzyMatch() {
XCTAssertEqual(
installedXcodes.first(withVersion: Version(xcodeVersion: "10.11.12")!),
InstalledXcode(path: Path("/Applications/Xcode-10.11.12-release.candidate.app")!, version: Version(xcodeVersion: "10.11.12 Release Candidate")!)
)
// With build metadata
XCTAssertEqual(
installedXcodes.first(withVersion: Version(xcodeVersion: "11.12.13")!),
InstalledXcode(path: Path("/Applications/Xcode-11.12.13-release.candidate.app")!, version: Version(11, 12, 13, prereleaseIdentifiers: ["Release", "Candidate"], buildMetadataIdentifiers: ["DEF456"]))
)
}
func test_installedXcodes_noMatch() {
XCTAssertEqual(
installedXcodes.first(withVersion: Version(xcodeVersion: "3.4.5")!),
nil
)
}
func test_installedXcodes_multipleMatches() {
XCTAssertEqual(
installedXcodes.first(withVersion: Version(xcodeVersion: "4.5.6")!),
nil
)
}
func test_XcodeVersionEqualWithoutAllIdentifiers() {
XCTAssertTrue(Version("12.0.0-beta")!.isEqualWithoutAllIdentifiers(to: Version(xcodeVersion: "12")!))
XCTAssertTrue(Version("12.0.0-beta")!.isEqualWithoutAllIdentifiers(to: Version(xcodeVersion: "12.0")!))
XCTAssertTrue(Version("12.0.0-beta")!.isEqualWithoutAllIdentifiers(to: Version(xcodeVersion: "12.0.0")!))
XCTAssertTrue(Version("12.0.0-beta+qwerty")!.isEqualWithoutAllIdentifiers(to: Version(xcodeVersion: "12")!))
XCTAssertTrue(Version("12.0.0-beta+qwerty")!.isEqualWithoutAllIdentifiers(to: Version(xcodeVersion: "12.0")!))
XCTAssertTrue(Version("12.0.0-beta+qwerty")!.isEqualWithoutAllIdentifiers(to: Version(xcodeVersion: "12.0.0")!))
}
func test_firstCompatibleXcode_prefersUniversal() {
// Test data with Universal, arm64-only, and x86_64-only builds
let universalXcode = Xcode(version: Version("26.2.0")!, url: URL(string: "https://example.com/Universal.xip")!, filename: "Universal.xip", releaseDate: nil, architectures: ["arm64", "x86_64"])
let arm64Xcode = Xcode(version: Version("26.2.0")!, url: URL(string: "https://example.com/arm64.xip")!, filename: "arm64.xip", releaseDate: nil, architectures: ["arm64"])
let x86Xcode = Xcode(version: Version("26.2.0")!, url: URL(string: "https://example.com/x86.xip")!, filename: "x86.xip", releaseDate: nil, architectures: ["x86_64"])
// On arm64 host, should prefer Universal over arm64-only
let arm64Host = [universalXcode, arm64Xcode, x86Xcode]
XCTAssertEqual(arm64Host.firstCompatible(withVersion: Version("26.2.0")!, hostArchitecture: "arm64")?.filename, "Universal.xip")
// On x86_64 host, should prefer Universal over x86_64-only
let x86Host = [arm64Xcode, universalXcode, x86Xcode] // different order
XCTAssertEqual(x86Host.firstCompatible(withVersion: Version("26.2.0")!, hostArchitecture: "x86_64")?.filename, "Universal.xip")
}
func test_firstCompatibleXcode_fallsBackToMatchingArch() {
let arm64Xcode = Xcode(version: Version("26.2.0")!, url: URL(string: "https://example.com/arm64.xip")!, filename: "arm64.xip", releaseDate: nil, architectures: ["arm64"])
let x86Xcode = Xcode(version: Version("26.2.0")!, url: URL(string: "https://example.com/x86.xip")!, filename: "x86.xip", releaseDate: nil, architectures: ["x86_64"])
// On arm64 host without Universal, should get arm64
let arm64Only = [x86Xcode, arm64Xcode]
XCTAssertEqual(arm64Only.firstCompatible(withVersion: Version("26.2.0")!, hostArchitecture: "arm64")?.filename, "arm64.xip")
// On x86_64 host without Universal, should get x86_64
XCTAssertEqual(arm64Only.firstCompatible(withVersion: Version("26.2.0")!, hostArchitecture: "x86_64")?.filename, "x86.xip")
}
func test_firstCompatibleXcode_noArchitecturesFallsBackToFirst() {
let noArchXcode = Xcode(version: Version("26.2.0")!, url: URL(string: "https://example.com/noarch.xip")!, filename: "noarch.xip", releaseDate: nil, architectures: nil)
let arm64Xcode = Xcode(version: Version("26.2.0")!, url: URL(string: "https://example.com/arm64.xip")!, filename: "arm64.xip", releaseDate: nil, architectures: ["arm64"])
// When entry has no architectures, falls back to first match
let mixed = [arm64Xcode, noArchXcode]
XCTAssertEqual(mixed.firstCompatible(withVersion: Version("26.2.0")!, hostArchitecture: "x86_64")?.filename, "arm64.xip")
}
}