Skip to content

Commit 7eef0d5

Browse files
Bump ABI.CurrentVersion to 6.3 and ensure minor variances in JSON version numbers are permitted. (#1438)
This PR ensures that the JSON schema version 6.3 is considered "supported" in Swift Testing 6.3. As well, it suppresses a thrown error when the `version` field of a JSON record is slightly higher than the expected schema. For example, if we ask Swift Testing the ABI version corresponding to `VersionNumber(6, 3, 1)`, we'll get back `v6_3`, but then if we try to decode a JSON record whose `version` field equals `"6.3.1"`, we'll throw a version mismatch error. This error is now suppressed unless the versions really do mismatch. ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated. --------- Co-authored-by: Stuart Montgomery <[email protected]>
1 parent af7a094 commit 7eef0d5

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

Sources/Testing/ABI/ABI.Record.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,26 @@ extension ABI.Record: Codable {
7070
init(from decoder: any Decoder) throws {
7171
let container = try decoder.container(keyedBy: CodingKeys.self)
7272

73-
let versionNumber = try container.decode(VersionNumber.self, forKey: .version)
74-
if versionNumber != V.versionNumber {
73+
func validateVersionNumber(_ versionNumber: VersionNumber) throws {
74+
if versionNumber == V.versionNumber {
75+
return
76+
}
77+
#if !hasFeature(Embedded)
78+
// Allow for alternate version numbers if they correspond to the expected
79+
// record version (e.g. "1.2.3" might map to `v1_2_0` without a problem.)
80+
if ABI.version(forVersionNumber: versionNumber) == V.self {
81+
return
82+
}
83+
#endif
7584
throw DecodingError.dataCorrupted(
7685
DecodingError.Context(
7786
codingPath: decoder.codingPath + CollectionOfOne(CodingKeys.version as any CodingKey),
7887
debugDescription: "Unexpected record version \(versionNumber) (expected \(V.versionNumber))."
7988
)
8089
)
8190
}
91+
let versionNumber = try container.decode(VersionNumber.self, forKey: .version)
92+
try validateVersionNumber(versionNumber)
8293

8394
switch try container.decode(String.self, forKey: .kind) {
8495
case "test":

Sources/Testing/ABI/ABI.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ extension ABI {
4343
}
4444

4545
/// The current supported ABI version (ignoring any experimental versions.)
46-
typealias CurrentVersion = v0
46+
typealias CurrentVersion = v6_3
4747

4848
/// The highest defined and supported ABI version (including any experimental
4949
/// versions.)
@@ -55,10 +55,18 @@ extension ABI {
5555
/// - Parameters:
5656
/// - versionNumber: The ABI version number for which a concrete type is
5757
/// needed.
58+
/// - swiftCompilerVersion: The version number of the Swift compiler. This
59+
/// is used when `versionNumber` is greater than the highest known version
60+
/// to determine whether a version type can be returned. The default value
61+
/// is the version of the Swift compiler which was used to build the
62+
/// testing library.
5863
///
5964
/// - Returns: A type conforming to ``ABI/Version`` that represents the given
6065
/// ABI version, or `nil` if no such type exists.
61-
static func version(forVersionNumber versionNumber: VersionNumber = ABI.CurrentVersion.versionNumber) -> (any Version.Type)? {
66+
static func version(
67+
forVersionNumber versionNumber: VersionNumber,
68+
givenSwiftCompilerVersion swiftCompilerVersion: @autoclosure () -> VersionNumber = swiftCompilerVersion
69+
) -> (any Version.Type)? {
6270
if versionNumber > ABI.HighestVersion.versionNumber {
6371
// If the caller requested an ABI version higher than the current Swift
6472
// compiler version and it's not an ABI version we've explicitly defined,
@@ -71,7 +79,7 @@ extension ABI {
7179
// Note also that building an old version of Swift Testing with a newer
7280
// compiler may produce incorrect results here. We don't generally support
7381
// that configuration though.
74-
if versionNumber > swiftCompilerVersion {
82+
if versionNumber > swiftCompilerVersion() {
7583
return nil
7684
}
7785
}

Tests/TestingTests/SwiftPMTests.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,11 @@ struct SwiftPMTests {
302302

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

311312
@Test("Unsupported ABI version")

0 commit comments

Comments
 (0)