Skip to content

Commit 03399d1

Browse files
authored
[5.9] Fix Triple formatting in error messages (#6545)
* Fix `Triple` formatting in error messages Currently `Triple` is not `CustomStringConvertible`, which leads to issues when using it in string interpolations. It uses default implementation that prints all of the triple components separately, which isn't user-readable. rdar://107882041 * Fix `TripleTests.swift` build issue
1 parent b4a6e95 commit 03399d1

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Sources/Basics/Triple.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,10 @@ extension Triple {
298298
}
299299
}
300300

301+
extension Triple: CustomStringConvertible {
302+
public var description: String { tripleString }
303+
}
304+
301305
extension Triple.Error: CustomNSError {
302306
public var errorUserInfo: [String: Any] {
303307
[NSLocalizedDescriptionKey: "\(self)"]

Tests/BasicsTests/TripleTests.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift open source project
4+
//
5+
// Copyright (c) 2022 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import Basics
14+
import XCTest
15+
16+
final class TripleTests: XCTestCase {
17+
func testDescription() throws {
18+
let triple = try Triple("x86_64-pc-linux-gnu")
19+
XCTAssertEqual("foo \(triple) bar", "foo x86_64-pc-linux-gnu bar")
20+
}
21+
}

0 commit comments

Comments
 (0)