Skip to content
Merged
Show file tree
Hide file tree
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
15 changes: 13 additions & 2 deletions Sources/Testing/ABI/ABI.Record.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,26 @@ extension ABI.Record: Codable {
init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

let versionNumber = try container.decode(VersionNumber.self, forKey: .version)
if versionNumber != V.versionNumber {
func validateVersionNumber(_ versionNumber: VersionNumber) throws {
if versionNumber == V.versionNumber {
return
}
#if !hasFeature(Embedded)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we have to strictly match the patch version on embedded?

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe it's due to a more fundamental limitation: in Embedded Swift, there are no metatypes at all, so an expression such as V.self is not valid

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm no longer as enamoured of the "versions are types" approach and will probably make this code non-generic in a future release.

// Allow for alternate version numbers if they correspond to the expected
// record version (e.g. "1.2.3" might map to `v1_2_0` without a problem.)
if ABI.version(forVersionNumber: versionNumber) == V.self {
return
}
#endif
throw DecodingError.dataCorrupted(
DecodingError.Context(
codingPath: decoder.codingPath + CollectionOfOne(CodingKeys.version as any CodingKey),
debugDescription: "Unexpected record version \(versionNumber) (expected \(V.versionNumber))."
)
)
}
let versionNumber = try container.decode(VersionNumber.self, forKey: .version)
try validateVersionNumber(versionNumber)

switch try container.decode(String.self, forKey: .kind) {
case "test":
Expand Down
14 changes: 11 additions & 3 deletions Sources/Testing/ABI/ABI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extension ABI {
}

/// The current supported ABI version (ignoring any experimental versions.)
typealias CurrentVersion = v0
typealias CurrentVersion = v6_3

/// The highest defined and supported ABI version (including any experimental
/// versions.)
Expand All @@ -55,10 +55,18 @@ extension ABI {
/// - Parameters:
/// - versionNumber: The ABI version number for which a concrete type is
/// needed.
/// - swiftCompilerVersion: The version number of the Swift compiler. This
/// is used when `versionNumber` is greater than the highest known version
/// to determine whether a version type can be returned. The default value
/// is the version of the Swift compiler which was used to build the
/// testing library.
///
/// - Returns: A type conforming to ``ABI/Version`` that represents the given
/// ABI version, or `nil` if no such type exists.
static func version(forVersionNumber versionNumber: VersionNumber = ABI.CurrentVersion.versionNumber) -> (any Version.Type)? {
static func version(
forVersionNumber versionNumber: VersionNumber,
givenSwiftCompilerVersion swiftCompilerVersion: @autoclosure () -> VersionNumber = swiftCompilerVersion
) -> (any Version.Type)? {
if versionNumber > ABI.HighestVersion.versionNumber {
// If the caller requested an ABI version higher than the current Swift
// compiler version and it's not an ABI version we've explicitly defined,
Expand All @@ -71,7 +79,7 @@ extension ABI {
// Note also that building an old version of Swift Testing with a newer
// compiler may produce incorrect results here. We don't generally support
// that configuration though.
if versionNumber > swiftCompilerVersion {
if versionNumber > swiftCompilerVersion() {
return nil
}
}
Expand Down
9 changes: 5 additions & 4 deletions Tests/TestingTests/SwiftPMTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,11 @@ struct SwiftPMTests {

@Test("New-but-not-experimental ABI version")
func newButNotExperimentalABIVersion() async throws {
var versionNumber = ABI.CurrentVersion.versionNumber
versionNumber.patchComponent += 1
let version = try #require(ABI.version(forVersionNumber: versionNumber))
#expect(version.versionNumber == ABI.v0.versionNumber)
let currentVersionNumber = ABI.CurrentVersion.versionNumber
var newerVersionNumber = currentVersionNumber
newerVersionNumber.patchComponent += 1
let version = try #require(ABI.version(forVersionNumber: newerVersionNumber, givenSwiftCompilerVersion: newerVersionNumber))
#expect(version.versionNumber == currentVersionNumber)
}

@Test("Unsupported ABI version")
Expand Down