Skip to content

XCTest discovery support for non-Darwin platforms #499

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

owenv
Copy link
Collaborator

@owenv owenv commented May 9, 2025

Add a new target type for SwiftPM test runner executables used on Linux/Windows. XCTest discovery generates an entry point based on index store data. The index store implementation is a lightly edited version of what's in TSC. This will require some adoption work to generate the new test runner target in PIF - we should think about the best way to minimize the diff between Darwin and non-Darwin here (fyi @cmcgee1024 )

Add a new target type for SwiftPM test runner executables used on Linux/Windows.
XCTest discovery generates an entry point based on index store data. The index store
implementation is a lightly edited version of what's in TSC.
@owenv
Copy link
Collaborator Author

owenv commented May 9, 2025

@swift-ci test

@@ -649,7 +649,7 @@ public final class XCTestBundleProductTypeSpec : BundleProductTypeSpec, @uncheck
var (tableOpt, warnings, errors) = super.overridingBuildSettings(scope, platform: platform)
var table = tableOpt ?? MacroValueAssignmentTable(namespace: scope.namespace)

let isDeviceBuild = platform?.isDeploymentPlatform == true && platform?.identifier != "com.apple.platform.macosx"
let isDeviceBuild = platform?.isDeploymentPlatform == true && platform?.name != scope.evaluate(BuiltinMacros.HOST_PLATFORM)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an aside, this seems fundamentally flawed. There's no guarantee you're running the resulting binaries on the same host that built them, so it seems the host platform should enable this too.

Why simulators are excluded I'm not sure.

@@ -295,6 +295,7 @@ public enum PIF {
case executable = "com.apple.product-type.tool"
case hostBuildTool = "com.apple.product-type.tool.host-build"
case unitTest = "com.apple.product-type.bundle.unit-test"
case swiftpmTestRunner = "com.apple.product-type.tool.swiftpm-test-runner"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this need to be called "SwiftPM" test runner?

#if canImport(Testing)
import Testing
#endif

\(testObservationFragment(testOutputPath: "TODO"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO still supposed to be here?


private func testObservationFragment(testOutputPath: String) -> String {
"""
#if !os(Windows) // Test observation is not supported on Windows
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? Do we have a GitHub issue for this?

override func createTaskAction(_ cbc: CommandBuildContext, _ delegate: any TaskGenerationDelegate) -> (any PlannedTaskAction)? {
TestEntryPointGenerationTaskAction()
}

public func constructTasks(_ cbc: CommandBuildContext, _ delegate: any TaskGenerationDelegate, indexStorePaths: [Path], indexUnitBasePaths: [Path]) async {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we inject the necessary additional arguments without overriding constructTasks? Ever bare call to createTasks adds risk that we forget to update things as its signature or default behavior changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants