Skip to content

Commit 84c3c4d

Browse files
authored
Merge pull request #1928 from ahoppen/skip-if-plugin-not-supported
Skip plugin tests if the host toolchain doesn’t support SourceKit plugins
2 parents 76954e0 + 1bd9a57 commit 84c3c4d

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

Package.swift

+1
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ var targets: [Target] = [
404404
"SKLogging",
405405
"SKOptions",
406406
"SKUtilities",
407+
"SourceKitD",
407408
"SourceKitLSP",
408409
"SwiftExtensions",
409410
"ToolchainRegistry",

Sources/SKTestSupport/SkipUnless.swift

+34
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import LanguageServerProtocol
1515
import LanguageServerProtocolExtensions
1616
import RegexBuilder
1717
import SKLogging
18+
import SourceKitD
1819
import SourceKitLSP
1920
import SwiftExtensions
2021
import TSCExtensions
@@ -542,6 +543,39 @@ package actor SkipUnless {
542543
return locations.count > 0
543544
}
544545
}
546+
547+
package static func sourcekitdSupportsPlugin(
548+
file: StaticString = #filePath,
549+
line: UInt = #line
550+
) async throws {
551+
return try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(6, 2), file: file, line: line) {
552+
guard let sourcekitdPath = await ToolchainRegistry.forTesting.default?.sourcekitd else {
553+
struct NoSourceKitdFound: Error, CustomStringConvertible {
554+
var description: String = "Could not find SourceKitD"
555+
}
556+
throw NoSourceKitdFound()
557+
}
558+
let sourcekitd = try await DynamicallyLoadedSourceKitD.getOrCreate(
559+
dylibPath: sourcekitdPath,
560+
pluginPaths: try sourceKitPluginPaths
561+
)
562+
do {
563+
let response = try await sourcekitd.send(
564+
sourcekitd.dictionary([
565+
sourcekitd.keys.request: sourcekitd.requests.codeCompleteSetPopularAPI,
566+
sourcekitd.keys.codeCompleteOptions: [
567+
sourcekitd.keys.useNewAPI: 1
568+
],
569+
]),
570+
timeout: .seconds(defaultTimeout),
571+
fileContents: nil
572+
)
573+
return response[sourcekitd.keys.useNewAPI] == 1
574+
} catch {
575+
return false
576+
}
577+
}
578+
}
545579
}
546580

547581
// MARK: - Parsing Swift compiler version

Tests/SwiftSourceKitPluginTests/SwiftSourceKitPluginTests.swift

+32
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ final class SwiftSourceKitPluginTests: XCTestCase {
4545
}
4646

4747
func testBasicCompletion() async throws {
48+
try await SkipUnless.sourcekitdSupportsPlugin()
4849
let sourcekitd = try await getSourceKitD()
4950
let path = scratchFilePath()
5051
let positions = try await sourcekitd.openDocument(
@@ -166,6 +167,7 @@ final class SwiftSourceKitPluginTests: XCTestCase {
166167
}
167168

168169
func testEmptyName() async throws {
170+
try await SkipUnless.sourcekitdSupportsPlugin()
169171
let sourcekitd = try await getSourceKitD()
170172
let path = scratchFilePath()
171173
let positions = try await sourcekitd.openDocument(
@@ -205,6 +207,7 @@ final class SwiftSourceKitPluginTests: XCTestCase {
205207
}
206208

207209
func testMultipleFiles() async throws {
210+
try await SkipUnless.sourcekitdSupportsPlugin()
208211
let sourcekitd = try await getSourceKitD()
209212
let pathA = scratchFilePath(fileName: "a.swift")
210213
let pathB = scratchFilePath(fileName: "b.swift")
@@ -269,6 +272,7 @@ final class SwiftSourceKitPluginTests: XCTestCase {
269272
}
270273

271274
func testCancellation() async throws {
275+
try await SkipUnless.sourcekitdSupportsPlugin()
272276
let sourcekitd = try await getSourceKitD()
273277
let path = scratchFilePath()
274278
let positions = try await sourcekitd.openDocument(
@@ -335,6 +339,7 @@ final class SwiftSourceKitPluginTests: XCTestCase {
335339
}
336340

337341
func testEdits() async throws {
342+
try await SkipUnless.sourcekitdSupportsPlugin()
338343
let sourcekitd = try await getSourceKitD()
339344
let path = scratchFilePath()
340345
let positions = try await sourcekitd.openDocument(
@@ -393,6 +398,7 @@ final class SwiftSourceKitPluginTests: XCTestCase {
393398
}
394399

395400
func testDocumentation() async throws {
401+
try await SkipUnless.sourcekitdSupportsPlugin()
396402
let sourcekitd = try await getSourceKitD()
397403
let path = scratchFilePath()
398404
let positions = try await sourcekitd.openDocument(
@@ -439,6 +445,7 @@ final class SwiftSourceKitPluginTests: XCTestCase {
439445
}
440446

441447
func testNumBytesToErase() async throws {
448+
try await SkipUnless.sourcekitdSupportsPlugin()
442449
let sourcekitd = try await getSourceKitD()
443450
let path = scratchFilePath()
444451
let positions = try await sourcekitd.openDocument(
@@ -472,6 +479,7 @@ final class SwiftSourceKitPluginTests: XCTestCase {
472479
}
473480

474481
func testObjectLiterals() async throws {
482+
try await SkipUnless.sourcekitdSupportsPlugin()
475483
let sourcekitd = try await getSourceKitD()
476484
let path = scratchFilePath()
477485
let positions = try await sourcekitd.openDocument(
@@ -496,6 +504,7 @@ final class SwiftSourceKitPluginTests: XCTestCase {
496504
}
497505

498506
func testAddInitsToTopLevel() async throws {
507+
try await SkipUnless.sourcekitdSupportsPlugin()
499508
let sourcekitd = try await getSourceKitD()
500509
let path = scratchFilePath()
501510
let positions = try await sourcekitd.openDocument(
@@ -554,6 +563,7 @@ final class SwiftSourceKitPluginTests: XCTestCase {
554563
}
555564

556565
func testMembersGroupID() async throws {
566+
try await SkipUnless.sourcekitdSupportsPlugin()
557567
let sourcekitd = try await getSourceKitD()
558568
let path = scratchFilePath()
559569
let positions = try await sourcekitd.openDocument(
@@ -599,6 +609,7 @@ final class SwiftSourceKitPluginTests: XCTestCase {
599609
}
600610

601611
func testAddCallWithNoDefaultArgs() async throws {
612+
try await SkipUnless.sourcekitdSupportsPlugin()
602613
let sourcekitd = try await getSourceKitD()
603614
let path = scratchFilePath()
604615
let positions = try await sourcekitd.openDocument(
@@ -647,6 +658,7 @@ final class SwiftSourceKitPluginTests: XCTestCase {
647658
}
648659

649660
func testTextMatchScore() async throws {
661+
try await SkipUnless.sourcekitdSupportsPlugin()
650662
let sourcekitd = try await getSourceKitD()
651663
let path = scratchFilePath()
652664
let positions = try await sourcekitd.openDocument(
@@ -695,6 +707,7 @@ final class SwiftSourceKitPluginTests: XCTestCase {
695707
}
696708

697709
func testSemanticScore() async throws {
710+
try await SkipUnless.sourcekitdSupportsPlugin()
698711
let sourcekitd = try await getSourceKitD()
699712
let path = scratchFilePath()
700713
let positions = try await sourcekitd.openDocument(
@@ -737,6 +750,7 @@ final class SwiftSourceKitPluginTests: XCTestCase {
737750
}
738751

739752
func testSemanticScoreInit() async throws {
753+
try await SkipUnless.sourcekitdSupportsPlugin()
740754
let sourcekitd = try await getSourceKitD()
741755
let path = scratchFilePath()
742756
let positions = try await sourcekitd.openDocument(
@@ -785,6 +799,7 @@ final class SwiftSourceKitPluginTests: XCTestCase {
785799
}
786800

787801
func testSemanticScoreComponents() async throws {
802+
try await SkipUnless.sourcekitdSupportsPlugin()
788803
let sourcekitd = try await getSourceKitD()
789804
let path = scratchFilePath()
790805
let positions = try await sourcekitd.openDocument(
@@ -818,6 +833,7 @@ final class SwiftSourceKitPluginTests: XCTestCase {
818833
}
819834

820835
func testMemberAccessTypes() async throws {
836+
try await SkipUnless.sourcekitdSupportsPlugin()
821837
let sourcekitd = try await getSourceKitD()
822838
let path = scratchFilePath(fileName: "AnimalKit.swift")
823839
let positions = try await sourcekitd.openDocument(
@@ -864,6 +880,7 @@ final class SwiftSourceKitPluginTests: XCTestCase {
864880
}
865881

866882
func testTypeModule() async throws {
883+
try await SkipUnless.sourcekitdSupportsPlugin()
867884
let sourcekitd = try await getSourceKitD()
868885
let path = scratchFilePath(fileName: "AnimalKit.swift")
869886
let positions = try await sourcekitd.openDocument(
@@ -893,6 +910,7 @@ final class SwiftSourceKitPluginTests: XCTestCase {
893910
}
894911

895912
func testKeyword() async throws {
913+
try await SkipUnless.sourcekitdSupportsPlugin()
896914
let sourcekitd = try await getSourceKitD()
897915
let path = scratchFilePath()
898916
let positions = try await sourcekitd.openDocument(
@@ -918,6 +936,7 @@ final class SwiftSourceKitPluginTests: XCTestCase {
918936
}
919937

920938
func testSemanticScoreComponentsAsExtraUpdate() async throws {
939+
try await SkipUnless.sourcekitdSupportsPlugin()
921940
let sourcekitd = try await getSourceKitD()
922941
let path = scratchFilePath()
923942
let positions = try await sourcekitd.openDocument(
@@ -986,6 +1005,7 @@ final class SwiftSourceKitPluginTests: XCTestCase {
9861005
#if !os(macOS)
9871006
try XCTSkipIf(true, "AppKit is only defined on macOS")
9881007
#endif
1008+
try await SkipUnless.sourcekitdSupportsPlugin()
9891009
let sourcekitd = try await getSourceKitD()
9901010
let path = scratchFilePath()
9911011
let positions = try await sourcekitd.openDocument(
@@ -1034,6 +1054,7 @@ final class SwiftSourceKitPluginTests: XCTestCase {
10341054
}
10351055

10361056
func testPopularity() async throws {
1057+
try await SkipUnless.sourcekitdSupportsPlugin()
10371058
let sourcekitd = try await getSourceKitD()
10381059
let path = scratchFilePath()
10391060
let positions = try await sourcekitd.openDocument(
@@ -1123,6 +1144,7 @@ final class SwiftSourceKitPluginTests: XCTestCase {
11231144
}
11241145

11251146
func testScopedPopularity() async throws {
1147+
try await SkipUnless.sourcekitdSupportsPlugin()
11261148
let sourcekitd = try await getSourceKitD()
11271149
let path = scratchFilePath()
11281150
let positions = try await sourcekitd.openDocument(
@@ -1196,6 +1218,7 @@ final class SwiftSourceKitPluginTests: XCTestCase {
11961218
}
11971219

11981220
func testModulePopularity() async throws {
1221+
try await SkipUnless.sourcekitdSupportsPlugin()
11991222
let sourcekitd = try await getSourceKitD()
12001223
let path = scratchFilePath()
12011224
let positions = try await sourcekitd.openDocument(
@@ -1262,6 +1285,7 @@ final class SwiftSourceKitPluginTests: XCTestCase {
12621285
}
12631286

12641287
func testFlair() async throws {
1288+
try await SkipUnless.sourcekitdSupportsPlugin()
12651289
let sourcekitd = try await getSourceKitD()
12661290
let path = scratchFilePath()
12671291
let positions = try await sourcekitd.openDocument(
@@ -1292,6 +1316,7 @@ final class SwiftSourceKitPluginTests: XCTestCase {
12921316
}
12931317

12941318
func testPluginFilterAndSortPerfAllMatch() async throws {
1319+
try await SkipUnless.sourcekitdSupportsPlugin()
12951320
let sourcekitd = try await getSourceKitD()
12961321
let path = scratchFilePath()
12971322
let (position, recent) = try await sourcekitd.perfTestSetup(path: path)
@@ -1331,6 +1356,7 @@ final class SwiftSourceKitPluginTests: XCTestCase {
13311356
}
13321357

13331358
func testPluginFilterAndSortPerfFiltered() async throws {
1359+
try await SkipUnless.sourcekitdSupportsPlugin()
13341360
let sourcekitd = try await getSourceKitD()
13351361
let path = scratchFilePath()
13361362
let (position, recent) = try await sourcekitd.perfTestSetup(path: path)
@@ -1399,6 +1425,7 @@ final class SwiftSourceKitPluginTests: XCTestCase {
13991425
])
14001426

14011427
// Open document in sourcekitd
1428+
try await SkipUnless.sourcekitdSupportsPlugin()
14021429
let sourcekitd = try await getSourceKitD()
14031430
let libBPath = try project.uri(for: "LibB.swift").pseudoPath
14041431
try await sourcekitd.openDocument(
@@ -1471,6 +1498,7 @@ final class SwiftSourceKitPluginTests: XCTestCase {
14711498
""",
14721499
])
14731500

1501+
try await SkipUnless.sourcekitdSupportsPlugin()
14741502
let sourcekitd = try await getSourceKitD()
14751503
let mainPath = try project.uri(for: "Main.swift").pseudoPath
14761504
try await sourcekitd.openDocument(
@@ -1503,6 +1531,7 @@ final class SwiftSourceKitPluginTests: XCTestCase {
15031531
#if !os(macOS)
15041532
try XCTSkipIf(true, "Soft deprecation is only defined for macOS in this test case")
15051533
#endif
1534+
try await SkipUnless.sourcekitdSupportsPlugin()
15061535
let sourcekitd = try await getSourceKitD()
15071536
let path = scratchFilePath()
15081537
let positions = try await sourcekitd.openDocument(
@@ -1568,6 +1597,7 @@ final class SwiftSourceKitPluginTests: XCTestCase {
15681597
}
15691598

15701599
func testActorKind() async throws {
1600+
try await SkipUnless.sourcekitdSupportsPlugin()
15711601
let sourcekitd = try await getSourceKitD()
15721602
let path = scratchFilePath()
15731603
let positions = try await sourcekitd.openDocument(
@@ -1587,6 +1617,7 @@ final class SwiftSourceKitPluginTests: XCTestCase {
15871617
}
15881618

15891619
func testMacroKind() async throws {
1620+
try await SkipUnless.sourcekitdSupportsPlugin()
15901621
let sourcekitd = try await getSourceKitD()
15911622
let path = scratchFilePath()
15921623
let positions = try await sourcekitd.openDocument(
@@ -1616,6 +1647,7 @@ final class SwiftSourceKitPluginTests: XCTestCase {
16161647
}
16171648

16181649
func testMaxResults() async throws {
1650+
try await SkipUnless.sourcekitdSupportsPlugin()
16191651
let sourcekitd = try await getSourceKitD()
16201652
let path = scratchFilePath()
16211653
var sourceText = "//dummy\n";

0 commit comments

Comments
 (0)