-
Notifications
You must be signed in to change notification settings - Fork 314
Add a new test project type that uses a custom build server #2035
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
Conversation
Not to self: If this gets merged before #2032, then we can update that PR to use the following test case, using the new build server test infrastructure. Updated test
func testUseResponseFileIfTooManyArguments() async throws {
// The build system returns too many arguments to fit them into a command line invocation, so we need to use a
// response file to invoke the indexer.
final class BuildServer: CustomBuildServer {
private let projectRoot: URL
private var testFileURL: URL { projectRoot.appendingPathComponent("Test File.swift") }
init(projectRoot: URL, connectionToSourceKitLSP: any LanguageServerProtocol.Connection) {
self.projectRoot = projectRoot
}
func initializeBuildRequest(_ request: InitializeBuildRequest) async throws -> InitializeBuildResponse {
return initializationResponse(
initializeData: SourceKitInitializeBuildResponseData(
indexDatabasePath: try projectRoot.appendingPathComponent("index-db").filePath,
indexStorePath: try projectRoot.appendingPathComponent("index-store").filePath,
prepareProvider: true,
sourceKitOptionsProvider: true
)
)
}
func buildTargetSourcesRequest(_ request: BuildTargetSourcesRequest) async throws -> BuildTargetSourcesResponse {
return BuildTargetSourcesResponse(items: [
SourcesItem(
target: .dummy,
sources: [
SourceItem(uri: URI(testFileURL), kind: .file, generated: false)
]
)
])
}
func textDocumentSourceKitOptionsRequest(
_ request: TextDocumentSourceKitOptionsRequest
) async throws -> TextDocumentSourceKitOptionsResponse? {
var arguments =
[try testFileURL.filePath] + (0..<50_000).map { "-DTHIS_IS_AN_OPTION_THAT_CONTAINS_MANY_BYTES_\($0)" }
if let defaultSDKPath {
arguments += ["-sdk", defaultSDKPath]
}
return TextDocumentSourceKitOptionsResponse(
compilerArguments: arguments
)
}
}
let project = try await CustomBuildServerTestProject(
files: [
// File name contains a space to ensure we escape it in the response file.
"Test File.swift": """
func 1️⃣myTestFunc() {}
"""
],
buildServer: BuildServer.self,
enableBackgroundIndexing: true
)
try await project.testClient.send(PollIndexRequest())
let symbols = try await project.testClient.send(WorkspaceSymbolsRequest(query: "myTestFunc"))
XCTAssertEqual(
symbols,
[
.symbolInformation(
SymbolInformation(
name: "myTestFunc()",
kind: .function,
location: try project.location(from: "1️⃣", to: "1️⃣", in: "Test File.swift")
)
)
]
)
} |
@swift-ci Please test |
This allows us to more easily test behavior for build servers that have different behavior than SwiftPM and compile commands without having to implement the build server in Python.
e2e82f1
to
5c60d1d
Compare
@swift-ci Please test |
@@ -2,53 +2,61 @@ | |||
// | |||
// This source file is part of the Swift.org open source project | |||
// | |||
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors | |||
// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2025, right? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah… Probably from some copy-pasting
@swift-ci Please test Windows |
1 similar comment
@swift-ci Please test Windows |
This allows us to more easily test behavior for build servers that have different behavior than SwiftPM and compile commands without having to implement the build server in Python.