Skip to content

SKTestSupport: remove hardcoded version for XCTest #2076

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 1 commit into from
Mar 20, 2025
Merged
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
44 changes: 40 additions & 4 deletions Sources/SKTestSupport/IndexedSingleSwiftFileTestProject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,41 @@ import SwiftExtensions
import TSCBasic
import ToolchainRegistry

package struct WindowsPlatformInfo {
package struct DefaultProperties {
/// XCTEST_VERSION
/// specifies the version string of the bundled XCTest.
public let xctestVersion: String

/// SWIFT_TESTING_VERSION
/// specifies the version string of the bundled swift-testing.
public let swiftTestingVersion: String?

/// SWIFTC_FLAGS
/// Specifies extra flags to pass to swiftc from Swift Package Manager.
public let extraSwiftCFlags: [String]?
}

public let defaults: DefaultProperties
}
extension WindowsPlatformInfo.DefaultProperties: Decodable {
enum CodingKeys: String, CodingKey {
case xctestVersion = "XCTEST_VERSION"
case swiftTestingVersion = "SWIFT_TESTING_VERSION"
case extraSwiftCFlags = "SWIFTC_FLAGS"
}
}
extension WindowsPlatformInfo: Decodable {
enum CodingKeys: String, CodingKey {
case defaults = "DefaultProperties"
}
}
extension WindowsPlatformInfo {
package init(reading path: URL) throws {
let data: Data = try Data(contentsOf: path)
self = try PropertyListDecoder().decode(WindowsPlatformInfo.self, from: data)
}
}
package struct IndexedSingleSwiftFileTestProject {
enum Error: Swift.Error {
case swiftcNotFound
Expand Down Expand Up @@ -79,12 +114,13 @@ package struct IndexedSingleSwiftFileTestProject {
// The following are needed so we can import XCTest
let sdkUrl = URL(fileURLWithPath: sdk)
#if os(Windows)
let platform = sdkUrl.deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent()
let info = try WindowsPlatformInfo(reading: platform.appendingPathComponent("Info.plist"))
let xctestModuleDir =
sdkUrl
.deletingLastPathComponent()
.deletingLastPathComponent()
platform
.appendingPathComponent("Developer")
.appendingPathComponent("Library")
.appendingPathComponent("XCTest-development")
.appendingPathComponent("XCTest-\(info.defaults.xctestVersion)")
.appendingPathComponent("usr")
.appendingPathComponent("lib")
.appendingPathComponent("swift")
Expand Down