Skip to content

Commit 55b6d10

Browse files
committed
Update assertions to add more detail
`testSystemSwiftInterface` is called multiple times in a single test, add file/line to the test output so it's clear which case actually failed.
1 parent c0f1469 commit 55b6d10

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

Tests/SourceKitLSPTests/SwiftInterfaceTests.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,23 +114,25 @@ final class SwiftInterfaceTests: XCTestCase {
114114
_ testLoc: TestLocation,
115115
ws: SKSwiftPMTestWorkspace,
116116
swiftInterfaceFile: String,
117-
linePrefix: String
117+
linePrefix: String,
118+
file: StaticString = #filePath,
119+
line: UInt = #line
118120
) throws {
119121
try ws.openDocument(testLoc.url, language: .swift)
120122
let definition = try ws.sk.sendSync(DefinitionRequest(
121123
textDocument: testLoc.docIdentifier,
122124
position: testLoc.position))
123125
guard case .locations(let jump) = definition else {
124-
XCTFail("Response is not locations")
126+
XCTFail("Response is not locations", file: file, line: line)
125127
return
126128
}
127-
let location = try XCTUnwrap(jump.first)
128-
XCTAssertTrue(location.uri.pseudoPath.hasSuffix(swiftInterfaceFile), "Path was: '\(location.uri.pseudoPath)'")
129+
let location = try XCTUnwrap(jump.first, "No locations", file: file, line: line)
130+
XCTAssertTrue(location.uri.pseudoPath.hasSuffix(swiftInterfaceFile), "Expected '\(swiftInterfaceFile)' but returned path was '\(location.uri.pseudoPath)'", file: file, line: line)
129131
// load contents of swiftinterface
130-
let contents = try XCTUnwrap(location.uri.fileURL.flatMap({ try String(contentsOf: $0, encoding: .utf8) }))
132+
let contents = try XCTUnwrap(location.uri.fileURL.flatMap({ try String(contentsOf: $0, encoding: .utf8) }), "Missing path", file: file, line: line)
131133
let lineTable = LineTable(contents)
132-
let line = lineTable[location.range.lowerBound.line]
133-
XCTAssert(line.hasPrefix(linePrefix), "Full line was: '\(line)'")
134+
let lineText = lineTable[location.range.lowerBound.line]
135+
XCTAssert(lineText.hasPrefix(linePrefix), "Expected '\(linePrefix)' but first line was '\(lineText)'", file: file, line: line)
134136
ws.closeDocument(testLoc.url)
135137
}
136138

0 commit comments

Comments
 (0)