Skip to content

Commit 1715ac7

Browse files
committed
Make unsigned and static properties in TestFailureLocation SPI
Instead, expose `String` and `Int` variants publicly that can be passed directly in to `Issue.record` from `swift-testing`.
1 parent 178dc7a commit 1715ac7

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

Release Notes/600.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
- Pull request: https://github.com/apple/swift-syntax/pull/2587
9797

9898
- `SwiftSyntaxMacrosTestSupportFrameworkAgnostic`
99-
- Description: A version of the `SwiftSyntaxMacrosTestSupport` module that doesn't depend on `Foundation` or `XCTest` and can thus be used to write macro tests using `swift-testing`. Since swift-syntax can't depend on swift-testing (which would incur a circular dependency since swift-testing depends on swift-syntax), users need to manually specify a failure handler like the following, that fails the swift-testing test: `Issue.record(Comment(rawValue: $0.message), fileID: $0.location.fileID.description, filePath: $0.location.filePath.description, line: Int($0.location.line), column: Int($0.location.column))`
99+
- Description: A version of the `SwiftSyntaxMacrosTestSupport` module that doesn't depend on `Foundation` or `XCTest` and can thus be used to write macro tests using `swift-testing`. Since swift-syntax can't depend on swift-testing (which would incur a circular dependency since swift-testing depends on swift-syntax), users need to manually specify a failure handler like the following, that fails the swift-testing test: `Issue.record("\($0.message)", fileID: $0.location.fileID, filePath: $0.location.filePath, line: $0.location.line, column: $0.location.column)`
100100
- Pull request: https://github.com/apple/swift-syntax/pull/2647
101101

102102
## API Behavior Changes

Sources/SwiftSyntaxMacrosTestSupport/Assertions.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
public import SwiftSyntax
1515
public import SwiftSyntaxMacroExpansion
1616
public import SwiftSyntaxMacros
17-
public import SwiftSyntaxMacrosTestSupportFrameworkAgnostic
17+
@_spi(XCTestFailureLocation) public import SwiftSyntaxMacrosTestSupportFrameworkAgnostic
1818
private import XCTest
1919
#else
2020
import SwiftSyntax
2121
import SwiftSyntaxMacroExpansion
2222
import SwiftSyntaxMacros
23-
import SwiftSyntaxMacrosTestSupportFrameworkAgnostic
23+
@_spi(XCTestFailureLocation) import SwiftSyntaxMacrosTestSupportFrameworkAgnostic
2424
import XCTest
2525
#endif
2626

@@ -118,7 +118,7 @@ public func assertMacroExpansion(
118118
testFileName: testFileName,
119119
indentationWidth: indentationWidth,
120120
failureHandler: {
121-
XCTFail($0.message, file: $0.location.filePath, line: $0.location.line)
121+
XCTFail($0.message, file: $0.location.staticFilePath, line: $0.location.unsignedLine)
122122
},
123123
fileID: "", // Not used in the failure handler
124124
filePath: file,

Sources/SwiftSyntaxMacrosTestSupportFrameworkAgnostic/Assertions.swift

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,28 @@ import _SwiftSyntaxTestSupportFrameworkAgnostic
3535
/// Defines the location at which the a test failure should be anchored. This is typically the location where the
3636
/// assertion function is called.
3737
public struct TestFailureLocation {
38-
public let fileID: StaticString
39-
public let filePath: StaticString
40-
public let line: UInt
41-
public let column: UInt
38+
@_spi(XCTestFailureLocation) public let staticFileID: StaticString
39+
public var fileID: String { staticFileID.description }
40+
41+
@_spi(XCTestFailureLocation) public let staticFilePath: StaticString
42+
public var filePath: String { staticFilePath.description }
43+
44+
@_spi(XCTestFailureLocation) public let unsignedLine: UInt
45+
public var line: Int { Int(unsignedLine) }
46+
47+
@_spi(XCTestFailureLocation) public let unsignedColumn: UInt
48+
public var column: Int { Int(unsignedColumn) }
4249

4350
public init(
4451
fileID: StaticString,
4552
filePath: StaticString,
4653
line: UInt,
4754
column: UInt
4855
) {
49-
self.fileID = fileID
50-
self.filePath = filePath
51-
self.line = line
52-
self.column = column
56+
self.staticFileID = fileID
57+
self.staticFilePath = filePath
58+
self.unsignedLine = line
59+
self.unsignedColumn = column
5360
}
5461

5562
fileprivate init(underlying: _SwiftSyntaxTestSupportFrameworkAgnostic.TestFailureLocation) {
@@ -65,10 +72,10 @@ public struct TestFailureLocation {
6572
/// import `_SwiftSyntaxTestSupportFrameworkAgnostic` privately and don't expose its internal types.
6673
fileprivate var underlying: _SwiftSyntaxTestSupportFrameworkAgnostic.TestFailureLocation {
6774
_SwiftSyntaxTestSupportFrameworkAgnostic.TestFailureLocation(
68-
fileID: self.fileID,
69-
filePath: self.filePath,
70-
line: self.line,
71-
column: self.column
75+
fileID: self.staticFileID,
76+
filePath: self.staticFilePath,
77+
line: self.unsignedLine,
78+
column: self.unsignedColumn
7279
)
7380
}
7481
}

0 commit comments

Comments
 (0)