Skip to content

Commit b53b321

Browse files
authored
Merge pull request swiftlang#326 from heckj/filePath
convert tests from #file to using #filePath
2 parents 6511ca7 + c58d693 commit b53b321

File tree

7 files changed

+28
-28
lines changed

7 files changed

+28
-28
lines changed

Sources/LSPTestSupport/CheckCoding.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import XCTest
1717
///
1818
/// - parameter value: The value to encode/decode.
1919
/// - parameter json: The expected json encoding.
20-
public func checkCoding<T>(_ value: T, json: String, file: StaticString = #file, line: UInt = #line) where T: Codable & Equatable {
20+
public func checkCoding<T>(_ value: T, json: String, file: StaticString = #filePath, line: UInt = #line) where T: Codable & Equatable {
2121
let encoder = JSONEncoder()
2222
encoder.outputFormatting.insert(.prettyPrinted)
2323
if #available(macOS 10.13, *) {
@@ -57,7 +57,7 @@ private struct WrapFragment<T>: Equatable, Codable where T: Equatable & Codable
5757
///
5858
/// - parameter value: The value to encode/decode.
5959
/// - parameter json: The expected json encoding.
60-
public func checkDecoding<T>(json: String, expected value: T, file: StaticString = #file, line: UInt = #line) where T: Codable & Equatable {
60+
public func checkDecoding<T>(json: String, expected value: T, file: StaticString = #filePath, line: UInt = #line) where T: Codable & Equatable {
6161

6262
let wrappedStr = "{\"value\":\(json)}"
6363
let data = wrappedStr.data(using: .utf8)!
@@ -67,7 +67,7 @@ public func checkDecoding<T>(json: String, expected value: T, file: StaticString
6767
XCTAssertEqual(value, decodedValue, file: file, line: line)
6868
}
6969

70-
public func checkCoding<T>(_ value: T, json: String, userInfo: [CodingUserInfoKey: Any] = [:], file: StaticString = #file, line: UInt = #line, body: (T) -> Void) where T: Codable {
70+
public func checkCoding<T>(_ value: T, json: String, userInfo: [CodingUserInfoKey: Any] = [:], file: StaticString = #filePath, line: UInt = #line, body: (T) -> Void) where T: Codable {
7171
let encoder = JSONEncoder()
7272
encoder.outputFormatting.insert(.prettyPrinted)
7373
if #available(macOS 10.13, *) {

Tests/LSPLoggingTests/SupportTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ final class SupportTests: XCTestCase {
2323
messages.append((message, level))
2424
}
2525

26-
func check(expected: [(String, LogLevel)], file: StaticString = #file, line: UInt = #line) {
26+
func check(expected: [(String, LogLevel)], file: StaticString = #filePath, line: UInt = #line) {
2727
testLogger.flush()
2828
XCTAssert(messages.count == expected.count, "\(messages) does not match expected \(expected)", file: file, line: line)
2929
XCTAssert(zip(messages, expected).allSatisfy({ $0.0 == $0.1 }), "\(messages) does not match expected \(expected)", file: file, line: line)

Tests/LanguageServerProtocolJSONRPCTests/CodingTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ final class CodingTests: XCTestCase {
126126
"jsonrpc" : "2.0"
127127
}
128128
""")
129-
129+
130130
checkMessageCoding(ResponseError.cancelled, id: nil, json: """
131131
{
132132
"error" : {
@@ -216,7 +216,7 @@ final class CodingTests: XCTestCase {
216216

217217
let defaultCodingInfo: [CodingUserInfoKey: Any] = [CodingUserInfoKey.messageRegistryKey:MessageRegistry.lspProtocol]
218218

219-
private func checkMessageCoding<Request>(_ value: Request, id: RequestID, json: String, file: StaticString = #file, line: UInt = #line) where Request: RequestType & Equatable {
219+
private func checkMessageCoding<Request>(_ value: Request, id: RequestID, json: String, file: StaticString = #filePath, line: UInt = #line) where Request: RequestType & Equatable {
220220
checkCoding(JSONRPCMessage.request(value, id: id), json: json, userInfo: defaultCodingInfo, file: file, line: line) {
221221

222222
guard case JSONRPCMessage.request(let decodedValueOpaque, let decodedID) = $0, let decodedValue = decodedValueOpaque as? Request else {
@@ -229,7 +229,7 @@ private func checkMessageCoding<Request>(_ value: Request, id: RequestID, json:
229229
}
230230
}
231231

232-
private func checkMessageCoding<Notification>(_ value: Notification, json: String, file: StaticString = #file, line: UInt = #line) where Notification: NotificationType & Equatable {
232+
private func checkMessageCoding<Notification>(_ value: Notification, json: String, file: StaticString = #filePath, line: UInt = #line) where Notification: NotificationType & Equatable {
233233
checkCoding(JSONRPCMessage.notification(value), json: json, userInfo: defaultCodingInfo, file: file, line: line) {
234234

235235
guard case JSONRPCMessage.notification(let decodedValueOpaque) = $0, let decodedValue = decodedValueOpaque as? Notification else {
@@ -241,7 +241,7 @@ private func checkMessageCoding<Notification>(_ value: Notification, json: Strin
241241
}
242242
}
243243

244-
private func checkMessageCoding<Response>(_ value: Response, id: RequestID, json: String, file: StaticString = #file, line: UInt = #line) where Response: ResponseType & Equatable {
244+
private func checkMessageCoding<Response>(_ value: Response, id: RequestID, json: String, file: StaticString = #filePath, line: UInt = #line) where Response: ResponseType & Equatable {
245245

246246
let callback: JSONRPCMessage.ResponseTypeCallback = {
247247
return $0 == .string("unknown") ? nil : Response.self
@@ -262,7 +262,7 @@ private func checkMessageCoding<Response>(_ value: Response, id: RequestID, json
262262
}
263263
}
264264

265-
private func checkMessageCoding(_ value: ResponseError, id: RequestID?, json: String, file: StaticString = #file, line: UInt = #line) {
265+
private func checkMessageCoding(_ value: ResponseError, id: RequestID?, json: String, file: StaticString = #filePath, line: UInt = #line) {
266266
checkCoding(JSONRPCMessage.errorResponse(value, id: id), json: json, userInfo: defaultCodingInfo, file: file, line: line) {
267267

268268
guard case JSONRPCMessage.errorResponse(let decodedValue, let decodedID) = $0 else {
@@ -275,7 +275,7 @@ private func checkMessageCoding(_ value: ResponseError, id: RequestID?, json: St
275275
}
276276
}
277277

278-
private func checkMessageDecodingError(_ expected: MessageDecodingError, json: String, userInfo: [CodingUserInfoKey: Any] = defaultCodingInfo, file: StaticString = #file, line: UInt = #line) {
278+
private func checkMessageDecodingError(_ expected: MessageDecodingError, json: String, userInfo: [CodingUserInfoKey: Any] = defaultCodingInfo, file: StaticString = #filePath, line: UInt = #line) {
279279
let data = json.data(using: .utf8)!
280280
let decoder = JSONDecoder()
281281
decoder.userInfo = userInfo

Tests/LanguageServerProtocolJSONRPCTests/MessageParsingTests.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import XCTest
1717
final class MessageParsingTests: XCTestCase {
1818

1919
func testSplitMessage() {
20-
func check(_ string: String, contentLen: Int? = nil, restLen: Int?, file: StaticString = #file, line: UInt = #line) {
20+
func check(_ string: String, contentLen: Int? = nil, restLen: Int?, file: StaticString = #filePath, line: UInt = #line) {
2121
let bytes: [UInt8] = [UInt8](string.utf8)
2222
guard let ((content, header), rest) = try! bytes.jsonrpcSplitMessage() else {
2323
XCTAssert(restLen == nil, "expected non-empty field", file: file, line: line)
@@ -28,7 +28,7 @@ final class MessageParsingTests: XCTestCase {
2828
XCTAssertEqual(header.contentLength, contentLen, file: file, line: line)
2929
}
3030

31-
func checkError(_ string: String, _ expected: MessageDecodingError, file: StaticString = #file, line: UInt = #line) {
31+
func checkError(_ string: String, _ expected: MessageDecodingError, file: StaticString = #filePath, line: UInt = #line) {
3232
do {
3333
_ = try [UInt8](string.utf8).jsonrpcSplitMessage()
3434
XCTFail("missing expected error", file: file, line: line)
@@ -53,7 +53,7 @@ final class MessageParsingTests: XCTestCase {
5353
}
5454

5555
func testParseHeader() {
56-
func check(_ string: String, header expected: JSONRPCMessageHeader? = nil, restLen: Int?, file: StaticString = #file, line: UInt = #line) {
56+
func check(_ string: String, header expected: JSONRPCMessageHeader? = nil, restLen: Int?, file: StaticString = #filePath, line: UInt = #line) {
5757
let bytes: [UInt8] = [UInt8](string.utf8)
5858
guard let (header, rest) = try! bytes.jsonrcpParseHeader() else {
5959
XCTAssert(restLen == nil, "expected non-empty field", file: file, line: line)
@@ -63,7 +63,7 @@ final class MessageParsingTests: XCTestCase {
6363
XCTAssertEqual(header, expected, file: file, line: line)
6464
}
6565

66-
func checkErrorBytes(_ bytes: [UInt8], _ expected: MessageDecodingError, file: StaticString = #file, line: UInt = #line) {
66+
func checkErrorBytes(_ bytes: [UInt8], _ expected: MessageDecodingError, file: StaticString = #filePath, line: UInt = #line) {
6767
do {
6868
_ = try bytes.jsonrcpParseHeader()
6969
XCTFail("missing expected error", file: file, line: line)
@@ -74,7 +74,7 @@ final class MessageParsingTests: XCTestCase {
7474
}
7575
}
7676

77-
func checkError(_ string: String, _ expected: MessageDecodingError, file: StaticString = #file, line: UInt = #line) {
77+
func checkError(_ string: String, _ expected: MessageDecodingError, file: StaticString = #filePath, line: UInt = #line) {
7878
checkErrorBytes([UInt8](string.utf8), expected, file: file, line: line)
7979
}
8080

@@ -95,7 +95,7 @@ final class MessageParsingTests: XCTestCase {
9595
}
9696

9797
func testParseHeaderField() {
98-
func check(_ string: String, keyLen: Int? = nil, valueLen: Int? = nil, restLen: Int?, file: StaticString = #file, line: UInt = #line) {
98+
func check(_ string: String, keyLen: Int? = nil, valueLen: Int? = nil, restLen: Int?, file: StaticString = #filePath, line: UInt = #line) {
9999
let bytes: [UInt8] = [UInt8](string.utf8)
100100
guard let (kv, rest) = try! bytes.jsonrpcParseHeaderField() else {
101101
XCTAssert(restLen == nil, "expected non-empty field", file: file, line: line)
@@ -112,7 +112,7 @@ final class MessageParsingTests: XCTestCase {
112112
}
113113
}
114114

115-
func checkError(_ string: String, _ expected: MessageDecodingError, file: StaticString = #file, line: UInt = #line) {
115+
func checkError(_ string: String, _ expected: MessageDecodingError, file: StaticString = #filePath, line: UInt = #line) {
116116
do {
117117
_ = try [UInt8](string.utf8).jsonrpcParseHeaderField()
118118
XCTFail("missing expected error", file: file, line: line)

Tests/SKCoreTests/CompilationDatabaseTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import XCTest
1818

1919
final class CompilationDatabaseTests: XCTestCase {
2020
func testSplitShellEscapedCommand() {
21-
func check(_ str: String, _ expected: [String], file: StaticString=#file, line: UInt=#line) {
21+
func check(_ str: String, _ expected: [String], file: StaticString=#filePath, line: UInt=#line) {
2222
XCTAssertEqual(splitShellEscapedCommand(str), expected, file: file, line: line)
2323
}
2424

@@ -61,7 +61,7 @@ final class CompilationDatabaseTests: XCTestCase {
6161
func testEncodeCompDBCommand() {
6262
// Requires JSONEncoder.OutputFormatting.sortedKeys
6363
if #available(macOS 10.13, *) {
64-
func check(_ cmd: CompilationDatabase.Command, _ expected: String, file: StaticString = #file, line: UInt = #line) {
64+
func check(_ cmd: CompilationDatabase.Command, _ expected: String, file: StaticString = #filePath, line: UInt = #line) {
6565
let encoder = JSONEncoder()
6666
encoder.outputFormatting.insert(.sortedKeys)
6767
let encodedString = try! String(data: encoder.encode(cmd), encoding: .utf8)
@@ -78,7 +78,7 @@ final class CompilationDatabaseTests: XCTestCase {
7878
}
7979

8080
func testDecodeCompDBCommand() {
81-
func check(_ str: String, _ expected: CompilationDatabase.Command, file: StaticString = #file, line: UInt = #line) {
81+
func check(_ str: String, _ expected: CompilationDatabase.Command, file: StaticString = #filePath, line: UInt = #line) {
8282
let cmd = try! JSONDecoder().decode(CompilationDatabase.Command.self, from: str.data(using: .utf8)!)
8383
XCTAssertEqual(cmd, expected, file: file, line: line)
8484
}
@@ -305,7 +305,7 @@ final class CompilationDatabaseTests: XCTestCase {
305305
}
306306
}
307307

308-
private func checkCompilationDatabaseBuildSystem(_ compdb: ByteString, file: StaticString = #file, line: UInt = #line, block: (CompilationDatabaseBuildSystem) -> ()) {
308+
private func checkCompilationDatabaseBuildSystem(_ compdb: ByteString, file: StaticString = #filePath, line: UInt = #line, block: (CompilationDatabaseBuildSystem) -> ()) {
309309
let fs = InMemoryFileSystem()
310310
XCTAssertNoThrow(try fs.createDirectory(AbsolutePath("/a")), file: file, line: line)
311311
XCTAssertNoThrow(try fs.writeFileContents(AbsolutePath("/a/compile_commands.json"), bytes: compdb), file: file, line: line)

Tests/SKSupportTests/SupportTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ import XCTest
1616

1717
final class SupportTests: XCTestCase {
1818

19-
func checkLines(_ string: String, _ expected: [String], file: StaticString = #file, line: UInt = #line) {
19+
func checkLines(_ string: String, _ expected: [String], file: StaticString = #filePath, line: UInt = #line) {
2020
let table = LineTable(string)
2121
XCTAssertEqual(table.map { String($0) }, expected, file: file, line: line)
2222
}
2323

24-
func checkOffsets(_ string: String, _ expected: [Int], file: StaticString = #file, line: UInt = #line) {
24+
func checkOffsets(_ string: String, _ expected: [Int], file: StaticString = #filePath, line: UInt = #line) {
2525
let table = LineTable(string)
2626
XCTAssertEqual(table.map { string.utf8.distance(from: string.startIndex, to: $0.startIndex) }, expected, file: file, line: line)
2727
}
@@ -68,7 +68,7 @@ final class SupportTests: XCTestCase {
6868
XCTAssertEqual(LineTable("\n")[1], "")
6969
}
7070

71-
func checkLineAndColumns(_ table: LineTable, _ utf8Offset: Int, _ expected: (line: Int, utf16Column: Int)?, file: StaticString = #file, line: UInt = #line) {
71+
func checkLineAndColumns(_ table: LineTable, _ utf8Offset: Int, _ expected: (line: Int, utf16Column: Int)?, file: StaticString = #filePath, line: UInt = #line) {
7272
switch (table.lineAndUTF16ColumnOf(utf8Offset: utf8Offset), expected) {
7373
case (nil, nil):
7474
break
@@ -79,11 +79,11 @@ final class SupportTests: XCTestCase {
7979
}
8080
}
8181

82-
func checkUTF8OffsetOf(_ table: LineTable, _ query: (line: Int, utf16Column: Int), _ expected: Int?, file: StaticString = #file, line: UInt = #line) {
82+
func checkUTF8OffsetOf(_ table: LineTable, _ query: (line: Int, utf16Column: Int), _ expected: Int?, file: StaticString = #filePath, line: UInt = #line) {
8383
XCTAssertEqual(table.utf8OffsetOf(line: query.line, utf16Column: query.utf16Column), expected, file: file, line: line)
8484
}
8585

86-
func checkUTF16ColumnAt(_ table: LineTable, _ query: (line: Int, utf8Column: Int), _ expected: Int?, file: StaticString = #file, line: UInt = #line) {
86+
func checkUTF16ColumnAt(_ table: LineTable, _ query: (line: Int, utf8Column: Int), _ expected: Int?, file: StaticString = #filePath, line: UInt = #line) {
8787
XCTAssertEqual(table.utf16ColumnAt(line: query.line, utf8Column: query.utf8Column), expected, file: file, line: line)
8888
}
8989

Tests/SKSwiftPMWorkspaceTests/SwiftPMWorkspaceTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ final class SwiftPMWorkspaceTests: XCTestCase {
512512
private func checkNot(
513513
_ pattern: String...,
514514
arguments: [String],
515-
file: StaticString = #file,
515+
file: StaticString = #filePath,
516516
line: UInt = #line)
517517
{
518518
if let index = arguments.firstIndex(of: pattern) {
@@ -526,7 +526,7 @@ private func checkNot(
526526
private func check(
527527
_ pattern: String...,
528528
arguments: [String],
529-
file: StaticString = #file,
529+
file: StaticString = #filePath,
530530
line: UInt = #line)
531531
{
532532
guard let index = arguments.firstIndex(of: pattern) else {

0 commit comments

Comments
 (0)