Skip to content

Commit aee36fd

Browse files
committed
Remove SkipUnless checks that always evaluate to true
We don’t support testing SourceKit-LSP using toolchains that don’t contain these features anymore.
1 parent 64f2aef commit aee36fd

15 files changed

+0
-469
lines changed

Sources/SKTestSupport/SkipUnless.swift

Lines changed: 0 additions & 334 deletions
Original file line numberDiff line numberDiff line change
@@ -109,309 +109,6 @@ package actor SkipUnless {
109109
}
110110
}
111111

112-
package static func sourcekitdHasSemanticTokensRequest(
113-
file: StaticString = #filePath,
114-
line: UInt = #line
115-
) async throws {
116-
try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(5, 11), file: file, line: line) {
117-
let testClient = try await TestSourceKitLSPClient()
118-
let uri = DocumentURI(for: .swift)
119-
testClient.openDocument("0.bitPattern", uri: uri)
120-
let response = try unwrap(
121-
await testClient.send(DocumentSemanticTokensRequest(textDocument: TextDocumentIdentifier(uri)))
122-
)
123-
124-
let tokens = SyntaxHighlightingTokens(lspEncodedTokens: response.data)
125-
126-
// If we don't have semantic token support in sourcekitd, the second token is an identifier based on the syntax
127-
// tree, not a property.
128-
return tokens.tokens != [
129-
SyntaxHighlightingToken(
130-
range: Position(line: 0, utf16index: 0)..<Position(line: 0, utf16index: 1),
131-
kind: .number,
132-
modifiers: []
133-
),
134-
SourceKitLSP.SyntaxHighlightingToken(
135-
range: Position(line: 0, utf16index: 2)..<Position(line: 0, utf16index: 12),
136-
kind: .identifier,
137-
modifiers: []
138-
),
139-
]
140-
}
141-
}
142-
143-
package static func sourcekitdSupportsRename(
144-
file: StaticString = #filePath,
145-
line: UInt = #line
146-
) async throws {
147-
try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(5, 11), file: file, line: line) {
148-
let testClient = try await TestSourceKitLSPClient()
149-
let uri = DocumentURI(for: .swift)
150-
let positions = testClient.openDocument("func 1️⃣test() {}", uri: uri)
151-
do {
152-
_ = try await testClient.send(
153-
RenameRequest(textDocument: TextDocumentIdentifier(uri), position: positions["1️⃣"], newName: "test2")
154-
)
155-
} catch let error as ResponseError {
156-
return error.message != "Running sourcekit-lsp with a version of sourcekitd that does not support rename"
157-
}
158-
return true
159-
}
160-
}
161-
162-
/// Checks whether the sourcekitd contains a fix to rename labels of enum cases correctly
163-
/// (https://github.com/apple/swift/pull/74241).
164-
package static func sourcekitdCanRenameEnumCaseLabels(
165-
file: StaticString = #filePath,
166-
line: UInt = #line
167-
) async throws {
168-
return try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(6, 0), file: file, line: line) {
169-
let testClient = try await TestSourceKitLSPClient()
170-
let uri = DocumentURI(for: .swift)
171-
let positions = testClient.openDocument(
172-
"""
173-
enum MyEnum {
174-
case 1️⃣myCase(2️⃣String)
175-
}
176-
""",
177-
uri: uri
178-
)
179-
180-
let renameResult = try await testClient.send(
181-
RenameRequest(textDocument: TextDocumentIdentifier(uri), position: positions["1️⃣"], newName: "myCase(label:)")
182-
)
183-
return renameResult?.changes == [uri: [TextEdit(range: Range(positions["2️⃣"]), newText: "label: ")]]
184-
}
185-
}
186-
187-
/// Whether clangd has support for the `workspace/indexedRename` request.
188-
package static func clangdSupportsIndexBasedRename(
189-
file: StaticString = #filePath,
190-
line: UInt = #line
191-
) async throws {
192-
try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(5, 11), file: file, line: line) {
193-
let testClient = try await TestSourceKitLSPClient()
194-
let uri = DocumentURI(for: .c)
195-
let positions = testClient.openDocument("void 1️⃣test() {}", uri: uri)
196-
do {
197-
_ = try await testClient.send(
198-
IndexedRenameRequest(
199-
textDocument: TextDocumentIdentifier(uri),
200-
oldName: "test",
201-
newName: "test2",
202-
positions: [uri: [positions["1️⃣"]]]
203-
)
204-
)
205-
} catch let error as ResponseError {
206-
return error.message != "method not found"
207-
}
208-
return true
209-
}
210-
}
211-
212-
/// SwiftPM moved the location where it stores Swift modules to a subdirectory in
213-
/// https://github.com/swiftlang/swift-package-manager/pull/7103.
214-
package static func swiftpmStoresModulesInSubdirectory(
215-
file: StaticString = #filePath,
216-
line: UInt = #line
217-
) async throws {
218-
try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(5, 11), file: file, line: line) {
219-
let workspace = try await SwiftPMTestProject(files: ["test.swift": ""])
220-
try await SwiftPMTestProject.build(at: workspace.scratchDirectory)
221-
let modulesDirectory = workspace.scratchDirectory
222-
.appendingPathComponent(".build")
223-
.appendingPathComponent("debug")
224-
.appendingPathComponent("Modules")
225-
.appendingPathComponent("MyLibrary.swiftmodule")
226-
return FileManager.default.fileExists(at: modulesDirectory)
227-
}
228-
}
229-
230-
package static func toolchainContainsSwiftFormat(
231-
file: StaticString = #filePath,
232-
line: UInt = #line
233-
) async throws {
234-
try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(5, 11), file: file, line: line) {
235-
return await ToolchainRegistry.forTesting.default?.swiftFormat != nil
236-
}
237-
}
238-
239-
/// Checks if the toolchain contains https://github.com/apple/swift/pull/74080.
240-
package static func sourcekitdReportsOverridableFunctionDefinitionsAsDynamic(
241-
file: StaticString = #filePath,
242-
line: UInt = #line
243-
) async throws {
244-
struct ExpectedLocationsResponse: Error {}
245-
246-
return try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(6, 0), file: file, line: line) {
247-
let project = try await IndexedSingleSwiftFileTestProject(
248-
"""
249-
protocol TestProtocol {
250-
func 1️⃣doThing()
251-
}
252-
253-
struct TestImpl: TestProtocol {}
254-
extension TestImpl {
255-
func 2️⃣doThing() { }
256-
}
257-
"""
258-
)
259-
260-
let response = try await project.testClient.send(
261-
DefinitionRequest(textDocument: TextDocumentIdentifier(project.fileURI), position: project.positions["1️⃣"])
262-
)
263-
guard case .locations(let locations) = response else {
264-
throw ExpectedLocationsResponse()
265-
}
266-
return locations.contains { $0.range == Range(project.positions["2️⃣"]) }
267-
}
268-
}
269-
270-
package static func sourcekitdReturnsRawDocumentationResponse(
271-
file: StaticString = #filePath,
272-
line: UInt = #line
273-
) async throws {
274-
struct ExpectedMarkdownContentsError: Error {}
275-
276-
return try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(6, 0), file: file, line: line) {
277-
// The XML-based doc comment conversion did not preserve `Precondition`.
278-
let testClient = try await TestSourceKitLSPClient()
279-
let uri = DocumentURI(for: .swift)
280-
let positions = testClient.openDocument(
281-
"""
282-
/// - Precondition: Must have an apple
283-
func 1️⃣test() {}
284-
""",
285-
uri: uri
286-
)
287-
let response = try await testClient.send(
288-
HoverRequest(textDocument: TextDocumentIdentifier(uri), position: positions["1️⃣"])
289-
)
290-
let hover = try XCTUnwrap(response, file: file, line: line)
291-
XCTAssertEqual(
292-
hover.range,
293-
Position(line: 1, utf16index: 5)..<Position(line: 1, utf16index: 9),
294-
file: file,
295-
line: line
296-
)
297-
guard case .markupContent(let content) = hover.contents else {
298-
throw ExpectedMarkdownContentsError()
299-
}
300-
return content.value.contains("Precondition")
301-
}
302-
}
303-
304-
/// Checks whether the index contains a fix that prevents it from adding relations to non-indexed locals
305-
/// (https://github.com/apple/swift/pull/72930).
306-
package static func indexOnlyHasContainedByRelationsToIndexedDecls(
307-
file: StaticString = #filePath,
308-
line: UInt = #line
309-
) async throws {
310-
return try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(6, 0), file: file, line: line) {
311-
let project = try await IndexedSingleSwiftFileTestProject(
312-
"""
313-
func foo() {}
314-
315-
func 1️⃣testFunc(x: String) {
316-
let myVar = foo
317-
}
318-
"""
319-
)
320-
let prepare = try await project.testClient.send(
321-
CallHierarchyPrepareRequest(
322-
textDocument: TextDocumentIdentifier(project.fileURI),
323-
position: project.positions["1️⃣"]
324-
)
325-
)
326-
let initialItem = try XCTUnwrap(prepare?.only)
327-
let calls = try await project.testClient.send(CallHierarchyOutgoingCallsRequest(item: initialItem))
328-
return calls != []
329-
}
330-
}
331-
332-
public static func swiftPMSupportsExperimentalPrepareForIndexing(
333-
file: StaticString = #filePath,
334-
line: UInt = #line
335-
) async throws {
336-
struct NoSwiftInToolchain: Error {}
337-
338-
return try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(6, 0), file: file, line: line) {
339-
guard let swift = await ToolchainRegistry.forTesting.default?.swift else {
340-
throw NoSwiftInToolchain()
341-
}
342-
343-
let result = try await Process.run(
344-
arguments: [swift.filePath, "build", "--help-hidden"],
345-
workingDirectory: nil
346-
)
347-
guard let output = String(bytes: try result.output.get(), encoding: .utf8) else {
348-
return false
349-
}
350-
return output.contains("--experimental-prepare-for-indexing")
351-
}
352-
}
353-
354-
package static func swiftPMStoresModulesForTargetAndHostInSeparateFolders(
355-
file: StaticString = #filePath,
356-
line: UInt = #line
357-
) async throws {
358-
struct NoSwiftInToolchain: Error {}
359-
360-
return try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(6, 0), file: file, line: line) {
361-
guard let swift = await ToolchainRegistry.forTesting.default?.swift else {
362-
throw NoSwiftInToolchain()
363-
}
364-
365-
let project = try await SwiftPMTestProject(
366-
files: [
367-
"Lib/MyFile.swift": """
368-
public func foo() {}
369-
""",
370-
"MyExec/MyExec.swift": """
371-
import Lib
372-
func bar() {
373-
foo()
374-
}
375-
""",
376-
"Plugins/MyPlugin/MyPlugin.swift": "",
377-
],
378-
manifest: """
379-
let package = Package(
380-
name: "MyLibrary",
381-
targets: [
382-
.target(name: "Lib"),
383-
.executableTarget(name: "MyExec", dependencies: ["Lib"]),
384-
.plugin(
385-
name: "MyPlugin",
386-
capability: .command(
387-
intent: .sourceCodeFormatting(),
388-
permissions: []
389-
),
390-
dependencies: ["MyExec"]
391-
)
392-
]
393-
)
394-
"""
395-
)
396-
do {
397-
// In older version of SwiftPM building `MyPlugin` followed by `Lib` resulted in an error about a redefinition
398-
// of Lib when building Lib.
399-
for target in ["MyPlugin", "Lib"] {
400-
var arguments = [
401-
try swift.filePath, "build", "--package-path", try project.scratchDirectory.filePath, "--target", target,
402-
]
403-
if let globalModuleCache = try globalModuleCache {
404-
arguments += ["-Xswiftc", "-module-cache-path", "-Xswiftc", try globalModuleCache.filePath]
405-
}
406-
try await Process.run(arguments: arguments, workingDirectory: nil)
407-
}
408-
return true
409-
} catch {
410-
return false
411-
}
412-
}
413-
}
414-
415112
/// A long test is a test that takes longer than 1-2s to execute.
416113
package static func longTestsEnabled() throws {
417114
if let value = ProcessInfo.processInfo.environment["SKIP_LONG_TESTS"], value == "1" || value == "YES" {
@@ -541,37 +238,6 @@ package actor SkipUnless {
541238
}
542239
}
543240

544-
/// Checks if sourcekitd contains https://github.com/swiftlang/swift/pull/71049
545-
package static func solverBasedCursorInfoWorksForMemoryOnlyFiles(
546-
file: StaticString = #filePath,
547-
line: UInt = #line
548-
) async throws {
549-
struct ExpectedLocationsResponse: Error {}
550-
551-
return try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(6, 0), file: file, line: line) {
552-
let testClient = try await TestSourceKitLSPClient()
553-
let uri = DocumentURI(for: .swift)
554-
let positions = testClient.openDocument(
555-
"""
556-
func foo() -> Int { 1 }
557-
func foo() -> String { "" }
558-
func test() {
559-
_ = 3️⃣foo()
560-
}
561-
""",
562-
uri: uri
563-
)
564-
565-
let response = try await testClient.send(
566-
DefinitionRequest(textDocument: TextDocumentIdentifier(uri), position: positions["3️⃣"])
567-
)
568-
guard case .locations(let locations) = response else {
569-
throw ExpectedLocationsResponse()
570-
}
571-
return locations.count > 0
572-
}
573-
}
574-
575241
package static func sourcekitdSupportsPlugin(
576242
file: StaticString = #filePath,
577243
line: UInt = #line

Sources/SKTestSupport/TestSourceKitLSPClient.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,6 @@ package final class TestSourceKitLSPClient: MessageHandler, Sendable {
156156
preInitialization: ((TestSourceKitLSPClient) -> Void)? = nil,
157157
cleanUp: @Sendable @escaping () -> Void = {}
158158
) async throws {
159-
if enableBackgroundIndexing {
160-
try await SkipUnless.swiftPMSupportsExperimentalPrepareForIndexing()
161-
}
162159
var options = options
163160
if let globalModuleCache = try globalModuleCache {
164161
options.swiftPMOrDefault.swiftCompilerFlags =

Tests/BuildSystemIntegrationTests/SwiftPMBuildSystemTests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ final class SwiftPMBuildSystemTests: XCTestCase {
125125
}
126126

127127
func testBasicSwiftArgs() async throws {
128-
try await SkipUnless.swiftpmStoresModulesInSubdirectory()
129128
try await withTestScratchDir { tempDir in
130129
try FileManager.default.createFiles(
131130
root: tempDir,

0 commit comments

Comments
 (0)