From 55b6d10ba11e4b13fde0ff908c2f1607d748c7cb Mon Sep 17 00:00:00 2001 From: Ben Barham Date: Thu, 17 Aug 2023 18:56:29 -0700 Subject: [PATCH] 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. --- .../SourceKitLSPTests/SwiftInterfaceTests.swift | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Tests/SourceKitLSPTests/SwiftInterfaceTests.swift b/Tests/SourceKitLSPTests/SwiftInterfaceTests.swift index d92bab9c1..bd8e426e8 100644 --- a/Tests/SourceKitLSPTests/SwiftInterfaceTests.swift +++ b/Tests/SourceKitLSPTests/SwiftInterfaceTests.swift @@ -114,23 +114,25 @@ final class SwiftInterfaceTests: XCTestCase { _ testLoc: TestLocation, ws: SKSwiftPMTestWorkspace, swiftInterfaceFile: String, - linePrefix: String + linePrefix: String, + file: StaticString = #filePath, + line: UInt = #line ) throws { try ws.openDocument(testLoc.url, language: .swift) let definition = try ws.sk.sendSync(DefinitionRequest( textDocument: testLoc.docIdentifier, position: testLoc.position)) guard case .locations(let jump) = definition else { - XCTFail("Response is not locations") + XCTFail("Response is not locations", file: file, line: line) return } - let location = try XCTUnwrap(jump.first) - XCTAssertTrue(location.uri.pseudoPath.hasSuffix(swiftInterfaceFile), "Path was: '\(location.uri.pseudoPath)'") + let location = try XCTUnwrap(jump.first, "No locations", file: file, line: line) + XCTAssertTrue(location.uri.pseudoPath.hasSuffix(swiftInterfaceFile), "Expected '\(swiftInterfaceFile)' but returned path was '\(location.uri.pseudoPath)'", file: file, line: line) // load contents of swiftinterface - let contents = try XCTUnwrap(location.uri.fileURL.flatMap({ try String(contentsOf: $0, encoding: .utf8) })) + let contents = try XCTUnwrap(location.uri.fileURL.flatMap({ try String(contentsOf: $0, encoding: .utf8) }), "Missing path", file: file, line: line) let lineTable = LineTable(contents) - let line = lineTable[location.range.lowerBound.line] - XCTAssert(line.hasPrefix(linePrefix), "Full line was: '\(line)'") + let lineText = lineTable[location.range.lowerBound.line] + XCTAssert(lineText.hasPrefix(linePrefix), "Expected '\(linePrefix)' but first line was '\(lineText)'", file: file, line: line) ws.closeDocument(testLoc.url) }