Skip to content

Commit 5e55203

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 a29f1ac commit 5e55203

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)

0 commit comments

Comments
 (0)