Skip to content

Commit ffdb50e

Browse files
authored
Add and fix missing Triple tests (#6842)
Vendored Swift Driver triple was not checked against a few tests that weren't brought over from TSC after `TSC.Triple` type was deprecated. We should fix those tests, especially as they verified that per-component equality for triples worked instead of the current string-based equality check. Also fixed some of the `Utilities/soundness.sh` script failures. Related to rdar://113967401
1 parent 087f541 commit ffdb50e

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

Sources/Basics/Triple+Basics.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ extension Triple {
186186

187187
/// Returns `true` if code compiled for `triple` can run on `self` value of ``Triple``.
188188
public func isRuntimeCompatible(with triple: Triple) -> Bool {
189+
guard self != triple else {
190+
return true
191+
}
192+
189193
if
190194
self.arch == triple.arch &&
191195
self.vendor == triple.vendor &&
@@ -204,7 +208,11 @@ extension Triple: CustomStringConvertible {
204208
}
205209

206210
extension Triple: Equatable {
207-
public static func == (lhs: Self, rhs: Self) -> Bool {
208-
lhs.triple == rhs.triple
211+
public static func ==(lhs: Triple, rhs: Triple) -> Bool {
212+
lhs.arch == rhs.arch
213+
&& lhs.vendor == rhs.vendor
214+
&& lhs.os == rhs.os
215+
&& lhs.environment == rhs.environment
216+
&& lhs.osVersion == rhs.osVersion
209217
}
210218
}

Tests/BasicsTests/TripleTests.swift

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,54 @@ final class TripleTests: XCTestCase {
164164
XCTAssertTriple("aarch64-unknown-linux-android", matches: (.aarch64, nil, nil, .linux, .android, .elf))
165165
XCTAssertTriple("x86_64-unknown-windows-msvc", matches: (.x86_64, nil, nil, .win32, .msvc, .coff))
166166
XCTAssertTriple("wasm32-unknown-wasi", matches: (.wasm32, nil, nil, .wasi, nil, .wasm))
167+
}
168+
169+
func testTriple() {
170+
let linux = try? Triple("x86_64-unknown-linux-gnu")
171+
XCTAssertNotNil(linux)
172+
XCTAssertEqual(linux!.os, .linux)
173+
XCTAssertEqual(linux!.osVersion, Triple.Version.zero)
174+
XCTAssertEqual(linux!.environment, .gnu)
175+
176+
let macos = try? Triple("x86_64-apple-macosx10.15")
177+
XCTAssertNotNil(macos!)
178+
XCTAssertEqual(macos!.osVersion, .init(parse: "10.15"))
179+
let newVersion = "10.12"
180+
let tripleString = macos!.tripleString(forPlatformVersion: newVersion)
181+
XCTAssertEqual(tripleString, "x86_64-apple-macosx10.12")
182+
let macosNoX = try? Triple("x86_64-apple-macos12.2")
183+
XCTAssertNotNil(macosNoX!)
184+
XCTAssertEqual(macosNoX!.os, .macosx)
185+
XCTAssertEqual(macosNoX!.osVersion, .init(parse: "12.2"))
186+
187+
let android = try? Triple("aarch64-unknown-linux-android24")
188+
XCTAssertNotNil(android)
189+
XCTAssertEqual(android!.os, .linux)
190+
XCTAssertEqual(android!.environment, .android)
191+
192+
let linuxWithABIVersion = try? Triple("x86_64-unknown-linux-gnu42")
193+
XCTAssertEqual(linuxWithABIVersion!.environment, .gnu)
194+
}
195+
196+
func testEquality() throws {
197+
let macOSTriple = try Triple("arm64-apple-macos")
198+
let macOSXTriple = try Triple("arm64-apple-macosx")
199+
XCTAssertEqual(macOSTriple, macOSXTriple)
200+
201+
let intelMacOSTriple = try Triple("x86_64-apple-macos")
202+
XCTAssertNotEqual(macOSTriple, intelMacOSTriple)
203+
204+
let linuxWithoutGNUABI = try Triple("x86_64-unknown-linux")
205+
let linuxWithGNUABI = try Triple("x86_64-unknown-linux-gnu")
206+
XCTAssertNotEqual(linuxWithoutGNUABI, linuxWithGNUABI)
207+
}
208+
209+
func testWASI() throws {
210+
let wasi = try Triple("wasm32-unknown-wasi")
211+
212+
// WASI dynamic libraries are only experimental,
213+
// but SwiftPM requires this property not to crash.
214+
_ = wasi.dynamicLibraryExtension
167215
}
168216

169217
func testIsRuntimeCompatibleWith() throws {

0 commit comments

Comments
 (0)