Skip to content

Commit c00a3cf

Browse files
committed
Switch most tests to use background indexing instead of building the project
There are still a few tests left that explicitly check the before and after build state, which I didn’t modify. rdar://128697501
1 parent 6eb47d3 commit c00a3cf

16 files changed

+51
-70
lines changed

Sources/SKTestSupport/SkipUnless.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,8 @@ public actor SkipUnless {
183183
line: UInt = #line
184184
) async throws {
185185
try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(5, 11), file: file, line: line) {
186-
let workspace = try await SwiftPMTestProject(
187-
files: ["test.swift": ""],
188-
build: true
189-
)
186+
let workspace = try await SwiftPMTestProject(files: ["test.swift": ""])
187+
try await SwiftPMTestProject.build(at: workspace.scratchDirectory)
190188
let modulesDirectory = workspace.scratchDirectory
191189
.appendingPathComponent(".build")
192190
.appendingPathComponent("debug")

Sources/SKTestSupport/SwiftPMTestProject.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ public class SwiftPMTestProject: MultiFileTestProject {
4040
files: [RelativeFileLocation: String],
4141
manifest: String = SwiftPMTestProject.defaultPackageManifest,
4242
workspaces: (URL) async throws -> [WorkspaceFolder] = { [WorkspaceFolder(uri: DocumentURI($0))] },
43-
build: Bool = false,
44-
allowBuildFailure: Bool = false,
4543
capabilities: ClientCapabilities = ClientCapabilities(),
4644
serverOptions: SourceKitLSPServer.Options = .testDefault,
4745
enableBackgroundIndexing: Bool = false,
@@ -79,13 +77,6 @@ public class SwiftPMTestProject: MultiFileTestProject {
7977
testName: testName
8078
)
8179

82-
if build {
83-
if allowBuildFailure {
84-
try? await Self.build(at: self.scratchDirectory)
85-
} else {
86-
try await Self.build(at: self.scratchDirectory)
87-
}
88-
}
8980
if pollIndex {
9081
// Wait for the indexstore-db to finish indexing
9182
_ = try await testClient.send(PollIndexRequest())

Tests/SourceKitLSPTests/CallHierarchyTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ final class CallHierarchyTests: XCTestCase {
200200
void FilePathIndex::2️⃣foo() {}
201201
""",
202202
],
203-
build: true
203+
enableBackgroundIndexing: true
204204
)
205205
let (uri, positions) = try project.openDocument("lib.h", language: .cpp)
206206
let result = try await project.testClient.send(

Tests/SourceKitLSPTests/DefinitionTests.swift

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class DefinitionTests: XCTestCase {
126126
}
127127
""",
128128
],
129-
build: true
129+
enableBackgroundIndexing: true
130130
)
131131
let (uri, positions) = try project.openDocument("test.cpp")
132132

@@ -177,7 +177,7 @@ class DefinitionTests: XCTestCase {
177177
]
178178
)
179179
""",
180-
build: true
180+
enableBackgroundIndexing: true
181181
)
182182

183183
let (uri, positions) = try project.openDocument("main.swift")
@@ -391,8 +391,7 @@ class DefinitionTests: XCTestCase {
391391
}
392392
""",
393393
],
394-
build: true,
395-
allowBuildFailure: true
394+
enableBackgroundIndexing: true
396395
)
397396

398397
let (bUri, bPositions) = try project.openDocument("FileB.swift")
@@ -428,12 +427,11 @@ class DefinitionTests: XCTestCase {
428427
.locations([Location(uri: aUri, range: Range(updatedAPositions["2️⃣"]))])
429428
)
430429

431-
try await SwiftPMTestProject.build(at: project.scratchDirectory)
432-
let afterBuilding = try await project.testClient.send(
430+
let afterChange = try await project.testClient.send(
433431
DefinitionRequest(textDocument: TextDocumentIdentifier(bUri), position: bPositions["1️⃣"])
434432
)
435433
XCTAssertEqual(
436-
afterBuilding,
434+
afterChange,
437435
.locations([Location(uri: aUri, range: Range(updatedAPositions["2️⃣"]))])
438436
)
439437
}
@@ -518,7 +516,7 @@ class DefinitionTests: XCTestCase {
518516
}
519517
""",
520518
],
521-
build: true
519+
enableBackgroundIndexing: true
522520
)
523521

524522
let definitionUri = try project.uri(for: "definition.swift")
@@ -550,8 +548,6 @@ class DefinitionTests: XCTestCase {
550548
])
551549
)
552550

553-
try await SwiftPMTestProject.build(at: project.scratchDirectory)
554-
555551
let resultAfterFileMove = try await project.testClient.send(
556552
DefinitionRequest(textDocument: TextDocumentIdentifier(callerUri), position: callerPositions["2️⃣"])
557553
)

Tests/SourceKitLSPTests/DependencyTrackingTests.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ final class DependencyTrackingTests: XCTestCase {
5151
// Semantic analysis: expect module import error.
5252
XCTAssertEqual(initialDiags.diagnostics.count, 1)
5353
if let diagnostic = initialDiags.diagnostics.first {
54-
// FIXME: The error message for the missing module is misleading on Darwin
55-
// https://github.com/apple/swift-package-manager/issues/5925
5654
XCTAssert(
5755
diagnostic.message.contains("Could not build Objective-C module")
5856
|| diagnostic.message.contains("No such module"),

Tests/SourceKitLSPTests/DocumentTestDiscoveryTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ final class DocumentTestDiscoveryTests: XCTestCase {
4848
targets: [.testTarget(name: "MyLibraryTests")]
4949
)
5050
""",
51-
build: true
51+
enableBackgroundIndexing: true
5252
)
5353

5454
let (uri, positions) = try project.openDocument("MyTests.swift")
@@ -1304,7 +1304,7 @@ final class DocumentTestDiscoveryTests: XCTestCase {
13041304
targets: [.testTarget(name: "MyLibraryTests")]
13051305
)
13061306
""",
1307-
build: true
1307+
enableBackgroundIndexing: true
13081308
)
13091309

13101310
let (uri, positions) = try project.openDocument("Test.m")
@@ -1363,7 +1363,7 @@ final class DocumentTestDiscoveryTests: XCTestCase {
13631363
targets: [.testTarget(name: "MyLibraryTests")]
13641364
)
13651365
""",
1366-
build: true
1366+
enableBackgroundIndexing: true
13671367
)
13681368

13691369
let (uri, positions) = try project.openDocument("Test.m")

Tests/SourceKitLSPTests/ImplementationTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ final class ImplementationTests: XCTestCase {
296296
struct MyStruct: 2️⃣MyProto {}
297297
""",
298298
],
299-
build: true
299+
enableBackgroundIndexing: true
300300
)
301301

302302
let (aUri, aPositions) = try project.openDocument("a.swift")

Tests/SourceKitLSPTests/IndexTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ final class IndexTests: XCTestCase {
4949
]
5050
)
5151
""",
52-
build: true
52+
enableBackgroundIndexing: true
5353
)
5454

5555
let (libAUri, libAPositions) = try project.openDocument("LibA.swift")

Tests/SourceKitLSPTests/MainFilesProviderTests.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ final class MainFilesProviderTests: XCTestCase {
4545
]
4646
)
4747
""",
48-
build: false,
4948
usePullDiagnostics: false
5049
)
5150

@@ -86,7 +85,6 @@ final class MainFilesProviderTests: XCTestCase {
8685
]
8786
)
8887
""",
89-
build: false,
9088
usePullDiagnostics: false
9189
)
9290

@@ -143,7 +141,7 @@ final class MainFilesProviderTests: XCTestCase {
143141
]
144142
)
145143
""",
146-
build: true,
144+
enableBackgroundIndexing: true,
147145
usePullDiagnostics: false
148146
)
149147

@@ -192,7 +190,7 @@ final class MainFilesProviderTests: XCTestCase {
192190
]
193191
)
194192
""",
195-
build: true,
193+
enableBackgroundIndexing: true,
196194
usePullDiagnostics: false
197195
)
198196

@@ -208,10 +206,11 @@ final class MainFilesProviderTests: XCTestCase {
208206
let newFancyLibraryContents = """
209207
#include "\(project.scratchDirectory.path)/Sources/shared.h"
210208
"""
211-
let fancyLibraryURL = try project.uri(for: "MyFancyLibrary.c").fileURL!
212-
try newFancyLibraryContents.write(to: fancyLibraryURL, atomically: false, encoding: .utf8)
213-
214-
try await SwiftPMTestProject.build(at: project.scratchDirectory)
209+
let fancyLibraryUri = try project.uri(for: "MyFancyLibrary.c")
210+
try newFancyLibraryContents.write(to: try XCTUnwrap(fancyLibraryUri.fileURL), atomically: false, encoding: .utf8)
211+
project.testClient.send(
212+
DidChangeWatchedFilesNotification(changes: [FileEvent(uri: fancyLibraryUri, type: .changed)])
213+
)
215214

216215
// 'MyFancyLibrary.c' now also includes 'shared.h'. Since it lexicographically preceeds MyLibrary, we should use its
217216
// build settings.

Tests/SourceKitLSPTests/RenameAssertions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func assertMultiFileRename(
145145
let project = try await SwiftPMTestProject(
146146
files: files,
147147
manifest: manifest,
148-
build: true,
148+
enableBackgroundIndexing: true,
149149
testName: testName
150150
)
151151
try preRenameActions(project)

Tests/SourceKitLSPTests/RenameTests.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ final class RenameTests: XCTestCase {
11141114
}
11151115
""",
11161116
],
1117-
build: true
1117+
enableBackgroundIndexing: true
11181118
)
11191119

11201120
let definitionUri = try project.uri(for: "definition.swift")
@@ -1157,7 +1157,6 @@ final class RenameTests: XCTestCase {
11571157
])
11581158
)
11591159

1160-
try await SwiftPMTestProject.build(at: project.scratchDirectory)
11611160
_ = try await project.testClient.send(PollIndexRequest())
11621161

11631162
let resultAfterFileMove = try await project.testClient.send(
@@ -1250,7 +1249,7 @@ final class RenameTests: XCTestCase {
12501249
}
12511250
""",
12521251
],
1253-
build: true
1252+
enableBackgroundIndexing: true
12541253
)
12551254
let (uri, positions) = try project.openDocument("FileA.swift")
12561255
let result = try await project.testClient.send(

Tests/SourceKitLSPTests/SwiftInterfaceTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ final class SwiftInterfaceTests: XCTestCase {
7979
]
8080
)
8181
""",
82-
build: true
82+
enableBackgroundIndexing: true
8383
)
8484

8585
let (mainUri, _) = try project.openDocument("main.swift")
@@ -176,7 +176,7 @@ final class SwiftInterfaceTests: XCTestCase {
176176
]
177177
)
178178
""",
179-
build: true
179+
enableBackgroundIndexing: true
180180
)
181181

182182
let (mainUri, mainPositions) = try project.openDocument("main.swift")

Tests/SourceKitLSPTests/SwiftPMIntegration.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ final class SwiftPMIntegrationTests: XCTestCase {
3131
}
3232
""",
3333
],
34-
build: true
34+
enableBackgroundIndexing: true
3535
)
3636

3737
let (otherUri, otherPositions) = try project.openDocument("Other.swift")
@@ -101,7 +101,7 @@ final class SwiftPMIntegrationTests: XCTestCase {
101101
}
102102
"""
103103
],
104-
build: true
104+
enableBackgroundIndexing: true
105105
)
106106

107107
let newFileUrl = project.scratchDirectory

Tests/SourceKitLSPTests/WorkspaceSymbolsTests.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,10 @@ class WorkspaceSymbolsTests: XCTestCase {
6060
],
6161
workspaces: {
6262
return [WorkspaceFolder(uri: DocumentURI($0.appendingPathComponent("packageB")))]
63-
}
63+
},
64+
enableBackgroundIndexing: true
6465
)
6566

66-
try await SwiftPMTestProject.build(at: project.scratchDirectory.appendingPathComponent("packageB"))
67-
6867
_ = try await project.testClient.send(PollIndexRequest())
6968
let response = try await project.testClient.send(WorkspaceSymbolsRequest(query: "funcFrom"))
7069

Tests/SourceKitLSPTests/WorkspaceTestDiscoveryTests.swift

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ final class WorkspaceTestDiscoveryTests: XCTestCase {
4646
"""
4747
],
4848
manifest: packageManifestWithTestTarget,
49-
build: true
49+
enableBackgroundIndexing: true
5050
)
5151

5252
let tests = try await project.testClient.send(WorkspaceTestsRequest())
@@ -141,7 +141,7 @@ final class WorkspaceTestDiscoveryTests: XCTestCase {
141141
"""
142142
],
143143
manifest: packageManifestWithTestTarget,
144-
build: true
144+
enableBackgroundIndexing: true
145145
)
146146

147147
let myTestsUri = try project.uri(for: "MyTests.swift")
@@ -304,8 +304,7 @@ final class WorkspaceTestDiscoveryTests: XCTestCase {
304304
"""
305305
],
306306
manifest: packageManifestWithTestTarget,
307-
build: true,
308-
allowBuildFailure: true
307+
enableBackgroundIndexing: true
309308
)
310309

311310
let tests = try await project.testClient.send(WorkspaceTestsRequest())
@@ -371,7 +370,7 @@ final class WorkspaceTestDiscoveryTests: XCTestCase {
371370
"""
372371
],
373372
manifest: packageManifestWithTestTarget,
374-
build: true
373+
enableBackgroundIndexing: true
375374
)
376375

377376
let (uri, positions) = try project.openDocument("MyTests.swift")
@@ -464,7 +463,7 @@ final class WorkspaceTestDiscoveryTests: XCTestCase {
464463
""",
465464
],
466465
manifest: packageManifestWithTestTarget,
467-
build: true
466+
enableBackgroundIndexing: true
468467
)
469468

470469
let (uri, positions) = try project.openDocument("MyFirstTests.swift")
@@ -536,7 +535,7 @@ final class WorkspaceTestDiscoveryTests: XCTestCase {
536535
"""
537536
],
538537
manifest: packageManifestWithTestTarget,
539-
build: true
538+
enableBackgroundIndexing: true
540539
)
541540

542541
let uri = try project.uri(for: "MyTests.swift")
@@ -935,7 +934,7 @@ final class WorkspaceTestDiscoveryTests: XCTestCase {
935934
targets: [.testTarget(name: "MyLibraryTests")]
936935
)
937936
""",
938-
build: true
937+
enableBackgroundIndexing: true
939938
)
940939

941940
let tests = try await project.testClient.send(WorkspaceTestsRequest())
@@ -992,7 +991,7 @@ final class WorkspaceTestDiscoveryTests: XCTestCase {
992991
targets: [.testTarget(name: "MyLibraryTests")]
993992
)
994993
""",
995-
build: true
994+
enableBackgroundIndexing: true
996995
)
997996

998997
let (uri, positions) = try project.openDocument("Test.m")

0 commit comments

Comments
 (0)