From e1d8de11b45a05fd090c8a6962c5c766ca8ad1e1 Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Mon, 17 Jun 2024 09:34:07 -0700 Subject: [PATCH] Skip `testJumpToSatisfiedProtocolRequirementInExtension` if the toolchain does not mark overridable function declarations as dynamic This test requires https://github.com/apple/swift/pull/74080 and should be skipped if the host toolchain does not have that change. --- Sources/SKTestSupport/SkipUnless.swift | 31 +++++++++++++++++++ Tests/SourceKitLSPTests/DefinitionTests.swift | 2 ++ 2 files changed, 33 insertions(+) diff --git a/Sources/SKTestSupport/SkipUnless.swift b/Sources/SKTestSupport/SkipUnless.swift index 761c76b5e..e6d0f20a9 100644 --- a/Sources/SKTestSupport/SkipUnless.swift +++ b/Sources/SKTestSupport/SkipUnless.swift @@ -233,6 +233,37 @@ public actor SkipUnless { } } + /// Checks if the toolchain contains https://github.com/apple/swift/pull/74080. + public static func sourcekitdReportsOverridableFunctionDefinitionsAsDynamic( + file: StaticString = #filePath, + line: UInt = #line + ) async throws { + struct ExpectedLocationsResponse: Error {} + + return try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(6, 0), file: file, line: line) { + let project = try await IndexedSingleSwiftFileTestProject( + """ + protocol TestProtocol { + func 1️⃣doThing() + } + + struct TestImpl: TestProtocol {} + extension TestImpl { + func 2️⃣doThing() { } + } + """ + ) + + let response = try await project.testClient.send( + DefinitionRequest(textDocument: TextDocumentIdentifier(project.fileURI), position: project.positions["1️⃣"]) + ) + guard case .locations(let locations) = response else { + throw ExpectedLocationsResponse() + } + return locations.contains { $0.range == Range(project.positions["2️⃣"]) } + } + } + public static func sourcekitdReturnsRawDocumentationResponse( file: StaticString = #filePath, line: UInt = #line diff --git a/Tests/SourceKitLSPTests/DefinitionTests.swift b/Tests/SourceKitLSPTests/DefinitionTests.swift index 9872b9991..265e5f04a 100644 --- a/Tests/SourceKitLSPTests/DefinitionTests.swift +++ b/Tests/SourceKitLSPTests/DefinitionTests.swift @@ -603,6 +603,8 @@ class DefinitionTests: XCTestCase { } func testJumpToSatisfiedProtocolRequirementInExtension() async throws { + try await SkipUnless.sourcekitdReportsOverridableFunctionDefinitionsAsDynamic() + let project = try await IndexedSingleSwiftFileTestProject( """ protocol TestProtocol {