Skip to content

[DNM] Try out enabling swift-testing by default. #7592

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

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 18 additions & 25 deletions Sources/CoreCommands/Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import struct PackageModel.EnabledSanitizers
import struct PackageModel.PackageIdentity
import class PackageModel.Manifest
import enum PackageModel.Sanitizer
import struct PackageModel.SupportedPlatform

import struct SPMBuildCore.BuildParameters

Expand Down Expand Up @@ -594,9 +595,8 @@ public struct TestLibraryOptions: ParsableArguments {
return callerSuppliedValue
}

// If the active package has a dependency on swift-testing, automatically enable support for it so that extra steps are not needed.
let workspace = try swiftCommandState.getActiveWorkspace()
let root = try swiftCommandState.getWorkspaceRoot()
let workspace = try swiftCommandState.getActiveWorkspace()
let rootManifests = try temp_await {
workspace.loadRootManifests(
packages: root.packages,
Expand All @@ -605,31 +605,24 @@ public struct TestLibraryOptions: ParsableArguments {
)
}

// Is swift-testing among the dependencies of the package being built?
// If so, enable support.
let isEnabledByDependency = rootManifests.values.lazy
.flatMap(\.dependencies)
.map(\.identity)
.map(String.init(describing:))
.contains("swift-testing")
if isEnabledByDependency {
swiftCommandState.observabilityScope.emit(debug: "Enabling swift-testing support due to its presence as a package dependency.")
return true
}

// Is swift-testing the package being built itself (unlikely)? If so,
// enable support.
let isEnabledByName = root.packages.lazy
.map(PackageIdentity.init(path:))
.map(String.init(describing:))
.contains("swift-testing")
if isEnabledByName {
swiftCommandState.observabilityScope.emit(debug: "Enabling swift-testing support because it is a root package.")
return true
let minimumPlatformsWithAsync: [String: SupportedPlatform] = [
"macos": SupportedPlatform(platform: .macOS, version: "10.15"),
"ios": SupportedPlatform(platform: .iOS, version: "13.0"),
"watchOS": SupportedPlatform(platform: .watchOS, version: "6.0"),
"tvOS": SupportedPlatform(platform: .tvOS, version: "13.0"),
]
for platformReq in rootManifests.values.lazy.flatMap(\.platforms) {
if let minimumPlatform = minimumPlatformsWithAsync[platformReq.platformName],
minimumPlatform.version > .init(platformReq.version) {
// The minimum platform version specified by the package does
// not support Swift Concurrency, so it cannot use swift-testing
// automatically.
return false
}
}

// Default to disabled since swift-testing is experimental (opt-in.)
return false
// Default to enabled.
return true
}

/// Get the set of enabled testing libraries.
Expand Down