-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Tests: Migrate PluginsBuildPlanTests to SwiftTesting and augment #9058
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
bkhouri
merged 1 commit into
swiftlang:main
from
bkhouri:t/main/gh8997_rdar157669245_migrate_PluginBuildPlan_to_ST_and_augment
Sep 11, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,91 +2,181 @@ | |
// | ||
// This source file is part of the Swift open source project | ||
// | ||
// Copyright (c) 2014-2024 Apple Inc. and the Swift project authors | ||
// Copyright (c) 2014-2025 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See http://swift.org/LICENSE.txt for license information | ||
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import Foundation | ||
import Basics | ||
import _InternalTestSupport | ||
@testable import SPMBuildCore | ||
import XCTest | ||
import PackageModel | ||
import Testing | ||
import _InternalTestSupport | ||
|
||
final class PluginsBuildPlanTests: XCTestCase { | ||
func testBuildToolsDatabasePath() async throws { | ||
try XCTSkipOnWindows(because: "Fails to build the project to due to incorrect Path handling. Possibly related to https://github.com/swiftlang/swift-package-manager/issues/8511") | ||
@testable import SPMBuildCore | ||
|
||
try await fixtureXCTest(name: "Miscellaneous/Plugins/MySourceGenPlugin") { fixturePath in | ||
let (stdout, _) = try await executeSwiftBuild(fixturePath, buildSystem: .native) | ||
XCTAssertMatch(stdout, .contains("Build complete!")) | ||
@Suite( | ||
.serialized, | ||
.tags( | ||
.TestSize.large, | ||
), | ||
) | ||
struct PluginsBuildPlanTests { | ||
@Test( | ||
.tags( | ||
.Feature.Command.Build, | ||
), | ||
.issue("https://github.com/swiftlang/swift-package-manager/issues/8511", relationship: .defect), // Fails to build the project to due to incorrect Path handling | ||
arguments: BuildConfiguration.allCases, | ||
) | ||
func buildToolsDatabasePath( | ||
config: BuildConfiguration, | ||
) async throws { | ||
try await withKnownIssue(isIntermittent: true) { | ||
try await fixture(name: "Miscellaneous/Plugins/MySourceGenPlugin") { fixturePath in | ||
let (stdout, _) = try await executeSwiftBuild( | ||
fixturePath, | ||
configuration: config, | ||
buildSystem: .native | ||
) | ||
#expect(stdout.contains("Build complete!")) | ||
// FIXME: This is temporary until build of plugin tools is extracted into its own command. | ||
XCTAssertTrue(localFileSystem.exists(fixturePath.appending(RelativePath(".build/plugin-tools.db")))) | ||
XCTAssertTrue(localFileSystem.exists(fixturePath.appending(RelativePath(".build/build.db")))) | ||
#expect(localFileSystem.exists(fixturePath.appending(RelativePath(".build/plugin-tools.db")))) | ||
#expect(localFileSystem.exists(fixturePath.appending(RelativePath(".build/build.db")))) | ||
} | ||
} when: { | ||
ProcessInfo.hostOperatingSystem == .windows | ||
} | ||
} | ||
|
||
func testCommandPluginDependenciesWhenCrossCompiling() async throws { | ||
// Command Plugin dependencies must be built for the host. | ||
// This test is only supported on macOS because that is the only | ||
// platform on which we can currently be sure of having a viable | ||
// cross-compilation environment (arm64->x86_64 or vice versa). | ||
// On Linux it is typically only possible to build for the host | ||
// environment unless cross-compilation SDKs are being used. | ||
#if !os(macOS) | ||
try XCTSkipIf(true, "test is only supported on macOS") | ||
#endif | ||
|
||
let hostToolchain = try UserToolchain(swiftSDK: .hostSwiftSDK(environment: [:]), environment: [:]) | ||
@Test( | ||
.serialized, | ||
.tags( | ||
.Feature.Command.Package.CommandPlugin, | ||
), | ||
.requireHostOS(.macOS), | ||
arguments: getBuildData(for: SupportedBuildSystemOnAllPlatforms), | ||
) | ||
func commandPluginDependenciesWhenNotCrossCompiling( | ||
buildData: BuildData, | ||
) async throws { | ||
let hostToolchain = try UserToolchain( | ||
swiftSDK: .hostSwiftSDK(environment: [:]), | ||
environment: [:] | ||
) | ||
let hostTriple = try! hostToolchain.targetTriple.withoutVersion().tripleString | ||
|
||
let x86Triple = "x86_64-apple-macosx" | ||
let armTriple = "arm64-apple-macosx" | ||
let targetTriple = hostToolchain.targetTriple.arch == .aarch64 ? x86Triple : armTriple | ||
|
||
let hostBinPathSegments = try buildData.buildSystem.binPath( | ||
for: buildData.config, | ||
triple: hostTriple, | ||
) | ||
let hostDebugBinPathSegments = try buildData.buildSystem.binPath( | ||
for: .debug, | ||
triple: hostTriple, | ||
) | ||
// By default, plugin dependencies are built for the host platform | ||
try await fixtureXCTest(name: "Miscellaneous/Plugins/CommandPluginTestStub") { fixturePath in | ||
try await fixture(name: "Miscellaneous/Plugins/CommandPluginTestStub") { fixturePath in | ||
let hostBinPath: AbsolutePath = fixturePath.appending(components: hostBinPathSegments) | ||
let hostDebugBinPath: AbsolutePath = fixturePath.appending(components: hostDebugBinPathSegments) | ||
let (stdout, stderr) = try await executeSwiftPackage( | ||
fixturePath, | ||
configuration: buildData.config, | ||
extraArgs: ["-v", "build-plugin-dependency"], | ||
buildSystem: .native, | ||
) | ||
XCTAssertMatch(stdout, .contains("Hello from dependencies-stub")) | ||
XCTAssertMatch(stderr, .contains("Build of product 'plugintool' complete!")) | ||
XCTAssertTrue( | ||
localFileSystem.exists( | ||
fixturePath.appending(RelativePath(".build/\(hostTriple)/debug/plugintool-tool")) | ||
) | ||
) | ||
XCTAssertTrue( | ||
localFileSystem.exists( | ||
fixturePath.appending(RelativePath(".build/\(hostTriple)/debug/placeholder")) | ||
) | ||
buildSystem: buildData.buildSystem, | ||
) | ||
#expect(stdout.contains("Hello from dependencies-stub")) | ||
if buildData.buildSystem == .native { | ||
#expect(stderr.contains("Build of product 'plugintool' complete!")) | ||
} | ||
let pluginToolName: String | ||
switch buildData.buildSystem { | ||
case .native: | ||
pluginToolName = "plugintool-tool" | ||
case .swiftbuild: | ||
pluginToolName = "plugintool" | ||
case .xcode: | ||
pluginToolName = "" | ||
Issue.record("Test has not been updated for this build system") | ||
} | ||
expectFileExists(at: hostBinPath.appending(pluginToolName)) | ||
expectFileExists(at: hostDebugBinPath.appending("placeholder")) | ||
} | ||
} | ||
|
||
@Test( | ||
.serialized, | ||
.tags( | ||
.Feature.Command.Package.CommandPlugin, | ||
), | ||
.requireHostOS(.macOS), | ||
arguments: getBuildData(for: SupportedBuildSystemOnAllPlatforms), | ||
) | ||
func commandPluginDependenciesWhenCrossCompiling( | ||
buildData: BuildData, | ||
) async throws { | ||
let hostToolchain = try UserToolchain( | ||
swiftSDK: .hostSwiftSDK(environment: [:]), | ||
environment: [:] | ||
) | ||
// let hostTriple = try! hostToolchain.targetTriple.withoutVersion().tripleString | ||
|
||
let x86Triple = "x86_64-apple-macosx" | ||
let armTriple = "arm64-apple-macosx" | ||
let targetTriple = hostToolchain.targetTriple.arch == .aarch64 ? x86Triple : armTriple | ||
|
||
let hostBinPathSegments = try buildData.buildSystem.binPath( | ||
for: buildData.config, | ||
) | ||
let targetDebugBinPathSegments = try buildData.buildSystem.binPath( | ||
for: .debug, | ||
triple: targetTriple, | ||
) | ||
|
||
// When cross compiling the final product, plugin dependencies should still be built for the host | ||
try await fixtureXCTest(name: "Miscellaneous/Plugins/CommandPluginTestStub") { fixturePath in | ||
let (stdout, stderr) = try await executeSwiftPackage( | ||
fixturePath, | ||
extraArgs: ["--triple", targetTriple, "-v", "build-plugin-dependency"], | ||
buildSystem: .native, | ||
) | ||
XCTAssertMatch(stdout, .contains("Hello from dependencies-stub")) | ||
XCTAssertMatch(stderr, .contains("Build of product 'plugintool' complete!")) | ||
XCTAssertTrue( | ||
localFileSystem.exists( | ||
fixturePath.appending(RelativePath(".build/\(hostTriple)/debug/plugintool-tool")) | ||
try await fixture(name: "Miscellaneous/Plugins/CommandPluginTestStub") { fixturePath in | ||
// let hostBinPath: AbsolutePath = fixturePath.appending(components: hostBinPathSegments) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: same as above |
||
let targetDebugBinPath: AbsolutePath = fixturePath.appending(components: targetDebugBinPathSegments) | ||
let hostBinPath = try fixturePath.appending( | ||
components: buildData.buildSystem.binPath( | ||
for: buildData.config, | ||
) | ||
) | ||
XCTAssertTrue( | ||
localFileSystem.exists( | ||
fixturePath.appending(RelativePath(".build/\(targetTriple)/debug/placeholder")) | ||
let targetBinPath = try fixturePath.appending( | ||
components: buildData.buildSystem.binPath( | ||
for: buildData.config, | ||
triple: targetTriple, | ||
) | ||
) | ||
let (stdout, stderr) = try await executeSwiftPackage( | ||
fixturePath, | ||
configuration: buildData.config, | ||
extraArgs: ["-v", "--triple", targetTriple, "build-plugin-dependency"], | ||
buildSystem: buildData.buildSystem, | ||
) | ||
#expect(stdout.contains("Hello from dependencies-stub")) | ||
if buildData.buildSystem == .native { | ||
#expect(stderr.contains("Build of product 'plugintool' complete!")) | ||
} | ||
let pluginToolName: String | ||
let pluginToolBinPath: AbsolutePath | ||
switch buildData.buildSystem { | ||
case .native: | ||
pluginToolName = "plugintool-tool" | ||
pluginToolBinPath = hostBinPath | ||
case .swiftbuild: | ||
pluginToolName = "plugintool" | ||
pluginToolBinPath = targetBinPath | ||
case .xcode: | ||
pluginToolName = "" | ||
pluginToolBinPath = AbsolutePath("/") | ||
Issue.record("Test has not been updated for this build system") | ||
} | ||
|
||
expectFileExists(at: targetDebugBinPath.appending("placeholder")) | ||
expectFileExists(at: pluginToolBinPath.appending(pluginToolName)) | ||
} | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: was this accidentally left in?