Skip to content

Switch most tests to use background indexing instead of building the project #1358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions Sources/SKTestSupport/SkipUnless.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,8 @@ public actor SkipUnless {
line: UInt = #line
) async throws {
try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(5, 11), file: file, line: line) {
let workspace = try await SwiftPMTestProject(
files: ["test.swift": ""],
build: true
)
let workspace = try await SwiftPMTestProject(files: ["test.swift": ""])
try await SwiftPMTestProject.build(at: workspace.scratchDirectory)
let modulesDirectory = workspace.scratchDirectory
.appendingPathComponent(".build")
.appendingPathComponent("debug")
Expand Down
9 changes: 0 additions & 9 deletions Sources/SKTestSupport/SwiftPMTestProject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ public class SwiftPMTestProject: MultiFileTestProject {
files: [RelativeFileLocation: String],
manifest: String = SwiftPMTestProject.defaultPackageManifest,
workspaces: (URL) async throws -> [WorkspaceFolder] = { [WorkspaceFolder(uri: DocumentURI($0))] },
build: Bool = false,
allowBuildFailure: Bool = false,
capabilities: ClientCapabilities = ClientCapabilities(),
serverOptions: SourceKitLSPServer.Options = .testDefault,
enableBackgroundIndexing: Bool = false,
Expand Down Expand Up @@ -79,13 +77,6 @@ public class SwiftPMTestProject: MultiFileTestProject {
testName: testName
)

if build {
if allowBuildFailure {
try? await Self.build(at: self.scratchDirectory)
} else {
try await Self.build(at: self.scratchDirectory)
}
}
if pollIndex {
// Wait for the indexstore-db to finish indexing
_ = try await testClient.send(PollIndexRequest())
Expand Down
2 changes: 1 addition & 1 deletion Tests/SourceKitLSPTests/CallHierarchyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ final class CallHierarchyTests: XCTestCase {
void FilePathIndex::2️⃣foo() {}
""",
],
build: true
enableBackgroundIndexing: true
)
let (uri, positions) = try project.openDocument("lib.h", language: .cpp)
let result = try await project.testClient.send(
Expand Down
16 changes: 6 additions & 10 deletions Tests/SourceKitLSPTests/DefinitionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class DefinitionTests: XCTestCase {
}
""",
],
build: true
enableBackgroundIndexing: true
)
let (uri, positions) = try project.openDocument("test.cpp")

Expand Down Expand Up @@ -177,7 +177,7 @@ class DefinitionTests: XCTestCase {
]
)
""",
build: true
enableBackgroundIndexing: true
)

let (uri, positions) = try project.openDocument("main.swift")
Expand Down Expand Up @@ -391,8 +391,7 @@ class DefinitionTests: XCTestCase {
}
""",
],
build: true,
allowBuildFailure: true
enableBackgroundIndexing: true
)

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

try await SwiftPMTestProject.build(at: project.scratchDirectory)
let afterBuilding = try await project.testClient.send(
let afterChange = try await project.testClient.send(
DefinitionRequest(textDocument: TextDocumentIdentifier(bUri), position: bPositions["1️⃣"])
)
XCTAssertEqual(
afterBuilding,
afterChange,
.locations([Location(uri: aUri, range: Range(updatedAPositions["2️⃣"]))])
)
}
Expand Down Expand Up @@ -518,7 +516,7 @@ class DefinitionTests: XCTestCase {
}
""",
],
build: true
enableBackgroundIndexing: true
)

let definitionUri = try project.uri(for: "definition.swift")
Expand Down Expand Up @@ -550,8 +548,6 @@ class DefinitionTests: XCTestCase {
])
)

try await SwiftPMTestProject.build(at: project.scratchDirectory)

let resultAfterFileMove = try await project.testClient.send(
DefinitionRequest(textDocument: TextDocumentIdentifier(callerUri), position: callerPositions["2️⃣"])
)
Expand Down
2 changes: 0 additions & 2 deletions Tests/SourceKitLSPTests/DependencyTrackingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ final class DependencyTrackingTests: XCTestCase {
// Semantic analysis: expect module import error.
XCTAssertEqual(initialDiags.diagnostics.count, 1)
if let diagnostic = initialDiags.diagnostics.first {
// FIXME: The error message for the missing module is misleading on Darwin
// https://github.com/apple/swift-package-manager/issues/5925
XCTAssert(
diagnostic.message.contains("Could not build Objective-C module")
|| diagnostic.message.contains("No such module"),
Expand Down
6 changes: 3 additions & 3 deletions Tests/SourceKitLSPTests/DocumentTestDiscoveryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ final class DocumentTestDiscoveryTests: XCTestCase {
targets: [.testTarget(name: "MyLibraryTests")]
)
""",
build: true
enableBackgroundIndexing: true
)

let (uri, positions) = try project.openDocument("MyTests.swift")
Expand Down Expand Up @@ -1304,7 +1304,7 @@ final class DocumentTestDiscoveryTests: XCTestCase {
targets: [.testTarget(name: "MyLibraryTests")]
)
""",
build: true
enableBackgroundIndexing: true
)

let (uri, positions) = try project.openDocument("Test.m")
Expand Down Expand Up @@ -1363,7 +1363,7 @@ final class DocumentTestDiscoveryTests: XCTestCase {
targets: [.testTarget(name: "MyLibraryTests")]
)
""",
build: true
enableBackgroundIndexing: true
)

let (uri, positions) = try project.openDocument("Test.m")
Expand Down
2 changes: 1 addition & 1 deletion Tests/SourceKitLSPTests/ImplementationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ final class ImplementationTests: XCTestCase {
struct MyStruct: 2️⃣MyProto {}
""",
],
build: true
enableBackgroundIndexing: true
)

let (aUri, aPositions) = try project.openDocument("a.swift")
Expand Down
2 changes: 1 addition & 1 deletion Tests/SourceKitLSPTests/IndexTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ final class IndexTests: XCTestCase {
]
)
""",
build: true
enableBackgroundIndexing: true
)

let (libAUri, libAPositions) = try project.openDocument("LibA.swift")
Expand Down
15 changes: 7 additions & 8 deletions Tests/SourceKitLSPTests/MainFilesProviderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ final class MainFilesProviderTests: XCTestCase {
]
)
""",
build: false,
usePullDiagnostics: false
)

Expand Down Expand Up @@ -86,7 +85,6 @@ final class MainFilesProviderTests: XCTestCase {
]
)
""",
build: false,
usePullDiagnostics: false
)

Expand Down Expand Up @@ -143,7 +141,7 @@ final class MainFilesProviderTests: XCTestCase {
]
)
""",
build: true,
enableBackgroundIndexing: true,
usePullDiagnostics: false
)

Expand Down Expand Up @@ -192,7 +190,7 @@ final class MainFilesProviderTests: XCTestCase {
]
)
""",
build: true,
enableBackgroundIndexing: true,
usePullDiagnostics: false
)

Expand All @@ -208,10 +206,11 @@ final class MainFilesProviderTests: XCTestCase {
let newFancyLibraryContents = """
#include "\(project.scratchDirectory.path)/Sources/shared.h"
"""
let fancyLibraryURL = try project.uri(for: "MyFancyLibrary.c").fileURL!
try newFancyLibraryContents.write(to: fancyLibraryURL, atomically: false, encoding: .utf8)

try await SwiftPMTestProject.build(at: project.scratchDirectory)
let fancyLibraryUri = try project.uri(for: "MyFancyLibrary.c")
try newFancyLibraryContents.write(to: try XCTUnwrap(fancyLibraryUri.fileURL), atomically: false, encoding: .utf8)
project.testClient.send(
DidChangeWatchedFilesNotification(changes: [FileEvent(uri: fancyLibraryUri, type: .changed)])
)

// 'MyFancyLibrary.c' now also includes 'shared.h'. Since it lexicographically preceeds MyLibrary, we should use its
// build settings.
Expand Down
2 changes: 1 addition & 1 deletion Tests/SourceKitLSPTests/RenameAssertions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func assertMultiFileRename(
let project = try await SwiftPMTestProject(
files: files,
manifest: manifest,
build: true,
enableBackgroundIndexing: true,
testName: testName
)
try preRenameActions(project)
Expand Down
5 changes: 2 additions & 3 deletions Tests/SourceKitLSPTests/RenameTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@ final class RenameTests: XCTestCase {
}
""",
],
build: true
enableBackgroundIndexing: true
)

let definitionUri = try project.uri(for: "definition.swift")
Expand Down Expand Up @@ -1157,7 +1157,6 @@ final class RenameTests: XCTestCase {
])
)

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

let resultAfterFileMove = try await project.testClient.send(
Expand Down Expand Up @@ -1250,7 +1249,7 @@ final class RenameTests: XCTestCase {
}
""",
],
build: true
enableBackgroundIndexing: true
)
let (uri, positions) = try project.openDocument("FileA.swift")
let result = try await project.testClient.send(
Expand Down
4 changes: 2 additions & 2 deletions Tests/SourceKitLSPTests/SwiftInterfaceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ final class SwiftInterfaceTests: XCTestCase {
]
)
""",
build: true
enableBackgroundIndexing: true
)

let (mainUri, _) = try project.openDocument("main.swift")
Expand Down Expand Up @@ -176,7 +176,7 @@ final class SwiftInterfaceTests: XCTestCase {
]
)
""",
build: true
enableBackgroundIndexing: true
)

let (mainUri, mainPositions) = try project.openDocument("main.swift")
Expand Down
4 changes: 2 additions & 2 deletions Tests/SourceKitLSPTests/SwiftPMIntegration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class SwiftPMIntegrationTests: XCTestCase {
}
""",
],
build: true
enableBackgroundIndexing: true
)

let (otherUri, otherPositions) = try project.openDocument("Other.swift")
Expand Down Expand Up @@ -101,7 +101,7 @@ final class SwiftPMIntegrationTests: XCTestCase {
}
"""
],
build: true
enableBackgroundIndexing: true
)

let newFileUrl = project.scratchDirectory
Expand Down
5 changes: 2 additions & 3 deletions Tests/SourceKitLSPTests/WorkspaceSymbolsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,10 @@ class WorkspaceSymbolsTests: XCTestCase {
],
workspaces: {
return [WorkspaceFolder(uri: DocumentURI($0.appendingPathComponent("packageB")))]
}
},
enableBackgroundIndexing: true
)

try await SwiftPMTestProject.build(at: project.scratchDirectory.appendingPathComponent("packageB"))

_ = try await project.testClient.send(PollIndexRequest())
let response = try await project.testClient.send(WorkspaceSymbolsRequest(query: "funcFrom"))

Expand Down
17 changes: 8 additions & 9 deletions Tests/SourceKitLSPTests/WorkspaceTestDiscoveryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ final class WorkspaceTestDiscoveryTests: XCTestCase {
"""
],
manifest: packageManifestWithTestTarget,
build: true
enableBackgroundIndexing: true
)

let tests = try await project.testClient.send(WorkspaceTestsRequest())
Expand Down Expand Up @@ -141,7 +141,7 @@ final class WorkspaceTestDiscoveryTests: XCTestCase {
"""
],
manifest: packageManifestWithTestTarget,
build: true
enableBackgroundIndexing: true
)

let myTestsUri = try project.uri(for: "MyTests.swift")
Expand Down Expand Up @@ -304,8 +304,7 @@ final class WorkspaceTestDiscoveryTests: XCTestCase {
"""
],
manifest: packageManifestWithTestTarget,
build: true,
allowBuildFailure: true
enableBackgroundIndexing: true
)

let tests = try await project.testClient.send(WorkspaceTestsRequest())
Expand Down Expand Up @@ -371,7 +370,7 @@ final class WorkspaceTestDiscoveryTests: XCTestCase {
"""
],
manifest: packageManifestWithTestTarget,
build: true
enableBackgroundIndexing: true
)

let (uri, positions) = try project.openDocument("MyTests.swift")
Expand Down Expand Up @@ -464,7 +463,7 @@ final class WorkspaceTestDiscoveryTests: XCTestCase {
""",
],
manifest: packageManifestWithTestTarget,
build: true
enableBackgroundIndexing: true
)

let (uri, positions) = try project.openDocument("MyFirstTests.swift")
Expand Down Expand Up @@ -536,7 +535,7 @@ final class WorkspaceTestDiscoveryTests: XCTestCase {
"""
],
manifest: packageManifestWithTestTarget,
build: true
enableBackgroundIndexing: true
)

let uri = try project.uri(for: "MyTests.swift")
Expand Down Expand Up @@ -935,7 +934,7 @@ final class WorkspaceTestDiscoveryTests: XCTestCase {
targets: [.testTarget(name: "MyLibraryTests")]
)
""",
build: true
enableBackgroundIndexing: true
)

let tests = try await project.testClient.send(WorkspaceTestsRequest())
Expand Down Expand Up @@ -992,7 +991,7 @@ final class WorkspaceTestDiscoveryTests: XCTestCase {
targets: [.testTarget(name: "MyLibraryTests")]
)
""",
build: true
enableBackgroundIndexing: true
)

let (uri, positions) = try project.openDocument("Test.m")
Expand Down
Loading