Skip to content

Commit

Permalink
Showing 2 changed files with 75 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Sources/SKTestSupport/SkipUnless.swift
Original file line number Diff line number Diff line change
@@ -477,6 +477,34 @@ package actor SkipUnless {
}
}

package static func canSwiftPMCompileForIOS(
file: StaticString = #filePath,
line: UInt = #line
) async throws {
return try await shared.skipUnlessSupported(allowSkippingInCI: true, file: file, line: line) {
#if os(macOS)
let project = try await SwiftPMTestProject(files: [
"MyFile.swift": """
public func foo() {}
"""
])
do {
try await SwiftPMTestProject.build(
at: project.scratchDirectory,
extraArguments: [
"--swift-sdk", "arm64-apple-ios",
]
)
return .featureSupported
} catch {
return .featureUnsupported(skipMessage: "Cannot build for iOS: \(error)")
}
#else
return .featureUnsupported(skipMessage: "Cannot build for iOS outside macOS by default")
#endif
}
}

package static func canCompileForWasm(
file: StaticString = #filePath,
line: UInt = #line
47 changes: 47 additions & 0 deletions Tests/SourceKitLSPTests/BackgroundIndexingTests.swift
Original file line number Diff line number Diff line change
@@ -1018,6 +1018,53 @@ final class BackgroundIndexingTests: XCTestCase {
)
}

func testUseSwiftSDKFlagsDuringPreparation() async throws {
try await SkipUnless.canSwiftPMCompileForIOS()

var options = SourceKitLSPOptions.testDefault()
options.swiftPMOrDefault.swiftSDK = "arm64-apple-ios"
let project = try await SwiftPMTestProject(
files: [
"Lib/Lib.swift": """
#if os(iOS)
public func foo() -> Int { 1 }
#endif
""",
"Client/Client.swift": """
import Lib
func test() -> String {
return foo()
}
""",
],
manifest: """
let package = Package(
name: "MyLibrary",
targets: [
.target(name: "Lib"),
.target(name: "Client", dependencies: ["Lib"]),
]
)
""",
options: options,
enableBackgroundIndexing: true
)

// Check that we get an error about the return type of `foo` (`Int`) not being convertible to the return type of
// `test` (`String`), which indicates that `Lib` had `foo` and was thus compiled for iOS
let (uri, _) = try project.openDocument("Client.swift")
let diagnostics = try await project.testClient.send(
DocumentDiagnosticsRequest(textDocument: TextDocumentIdentifier(uri))
)
XCTAssert(
(diagnostics.fullReport?.items ?? []).contains(where: {
$0.message == "Cannot convert return expression of type 'Int' to return type 'String'"
}),
"Did not get expected diagnostic: \(diagnostics)"
)
}

func testLibraryUsedByExecutableTargetAndPackagePlugin() async throws {
try await SkipUnless.swiftPMStoresModulesForTargetAndHostInSeparateFolders()
let project = try await SwiftPMTestProject(

0 comments on commit 6b533b3

Please sign in to comment.