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

Merged
merged 2 commits into from
Jun 4, 2025
Merged

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 )

@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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I called it that to differentiate it from other kinds of test runners like XCTRunner, but I'm not too attached to the name

#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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nope, fixed now so that this is provided via a CLI arg


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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is pulled in verbatim from SwiftPM

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I tried to do this at first, but I couldn't find an elegant way to differentiate the input types, especially since the handling of the index store is a bit unusual since the build system doesn't track the content inside it

@owenv
Copy link
Collaborator Author

owenv commented May 25, 2025

@swift-ci test

@owenv owenv force-pushed the owenv/test-discovery branch from 2415461 to 7a9476d Compare May 26, 2025 18:25
@owenv owenv force-pushed the owenv/test-discovery branch from 7a9476d to a2a03a9 Compare June 3, 2025 16:43
@owenv
Copy link
Collaborator Author

owenv commented Jun 3, 2025

@swift-ci test

@owenv owenv force-pushed the owenv/test-discovery branch from a2a03a9 to 0135fdb Compare June 3, 2025 17:37
@owenv
Copy link
Collaborator Author

owenv commented Jun 3, 2025

@swift-ci test

@owenv owenv merged commit 50d4c9c into main Jun 4, 2025
23 of 24 checks passed
@owenv owenv deleted the owenv/test-discovery branch June 4, 2025 18:05
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