Skip to content

Commit

Permalink
When the SourceKit plugins fail to load during testing, include the s…
Browse files Browse the repository at this point in the history
…earch base in the error
  • Loading branch information
ahoppen committed Jan 24, 2025
1 parent fe5644b commit 425102e
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions Sources/SKTestSupport/PluginPaths.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,34 @@ private func pluginPaths(relativeTo base: URL) -> PluginPaths? {
package var sourceKitPluginPaths: PluginPaths {
get throws {
struct PluginLoadingError: Error, CustomStringConvertible {
var description: String =
"Could not find SourceKit plugin. Ensure that you build the entire SourceKit-LSP package before running tests."
let searchBase: URL
var description: String {
// We can't declare a dependency from the test *target* on the SourceKit plugin *product*
// (https://github.com/swiftlang/swift-package-manager/issues/8245).
// We thus require a build before running the tests to ensure the plugin dylibs are in the build products
// folder.
"""
Could not find SourceKit plugin. Ensure that you build the entire SourceKit-LSP package before running tests.
Searching for plugin relative to \(searchBase)
"""
}
}

var base =
let base =
if let pluginPaths = ProcessInfo.processInfo.environment["SOURCEKIT_LSP_TEST_PLUGIN_PATHS"] {
URL(fileURLWithPath: pluginPaths)
} else {
xctestBundle
}
while base.pathComponents.count > 1 {
if let paths = pluginPaths(relativeTo: base) {
var searchPath = base
while searchPath.pathComponents.count > 1 {
if let paths = pluginPaths(relativeTo: searchPath) {
return paths
}
base = base.deletingLastPathComponent()
searchPath = searchPath.deletingLastPathComponent()
}

throw PluginLoadingError()
throw PluginLoadingError(searchBase: base)
}
}

0 comments on commit 425102e

Please sign in to comment.