Skip to content

Add test to check that we get semantic functionality even if a dependency module fails to prepare #1453

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
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
21 changes: 21 additions & 0 deletions Sources/SKTestSupport/SkipUnless.swift
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,27 @@ public actor SkipUnless {
}
}

public static func swiftPMSupportsExperimentalPrepareForIndexing(
file: StaticString = #filePath,
line: UInt = #line
) async throws {
struct NoSwiftInToolchain: Error {}

return try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(6, 0), file: file, line: line) {
guard let swift = await ToolchainRegistry.forTesting.default?.swift else {
throw NoSwiftInToolchain()
}

let process = Process(args: swift.pathString, "build", "--help-hidden")
try process.launch()
let result = try await process.waitUntilExit()
guard let output = String(bytes: try result.output.get(), encoding: .utf8) else {
return false
}
return output.contains("--experimental-prepare-for-indexing")
}
}

/// A long test is a test that takes longer than 1-2s to execute.
public static func longTestsEnabled() throws {
if let value = ProcessInfo.processInfo.environment["SKIP_LONG_TESTS"], value == "1" || value == "YES" {
Expand Down
50 changes: 47 additions & 3 deletions Tests/SourceKitLSPTests/BackgroundIndexingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,6 @@ final class BackgroundIndexingTests: XCTestCase {
}

func testLibraryUsedByExecutableTargetAndPackagePlugin() async throws {
try await SkipUnless.swiftpmStoresModulesInSubdirectory()
let project = try await SwiftPMTestProject(
files: [
"Lib/MyFile.swift": """
Expand All @@ -1022,8 +1021,6 @@ final class BackgroundIndexingTests: XCTestCase {
""",
],
manifest: """
// swift-tools-version: 5.7
import PackageDescription
let package = Package(
name: "MyLibrary",
targets: [
Expand All @@ -1049,4 +1046,51 @@ final class BackgroundIndexingTests: XCTestCase {
)
XCTAssertEqual(definition, .locations([try project.location(from: "1️⃣", to: "1️⃣", in: "MyFile.swift")]))
}

func testCrossModuleFunctionalityEvenIfLowLevelModuleHasErrors() async throws {
try await SkipUnless.swiftPMSupportsExperimentalPrepareForIndexing()
var serverOptions = SourceKitLSPServer.Options.testDefault
serverOptions.experimentalFeatures.insert(.swiftpmPrepareForIndexing)
let project = try await SwiftPMTestProject(
files: [
"LibA/LibA.swift": """
public func test() -> Invalid {
return ""
}
""",
"LibB/LibB.swift": """
import LibA

public func 1️⃣libBTest() -> Int {
return libATest()
}
""",
"MyExec/MyExec.swift": """
import LibB

func test() -> Int {
return 2️⃣libBTest()
}
""",
],
manifest: """
let package = Package(
name: "MyLibrary",
targets: [
.target(name: "LibA"),
.target(name: "LibB", dependencies: ["LibA"]),
.executableTarget(name: "MyExec", dependencies: ["LibB"]),
]
)
""",
serverOptions: serverOptions,
enableBackgroundIndexing: true
)

let (uri, positions) = try project.openDocument("MyExec.swift")
let response = try await project.testClient.send(
DefinitionRequest(textDocument: TextDocumentIdentifier(uri), position: positions["2️⃣"])
)
XCTAssertEqual(response, .locations([try project.location(from: "1️⃣", to: "1️⃣", in: "LibB.swift")]))
}
}