Skip to content

Commit 7493d6e

Browse files
authored
Move JSON ABI source files to prepare for v1. (#953)
At this time, we expect most of the "ABIv1" JSON schema will be the same as the current "ABIv0" one, so this PR reshuffles the source files supporting it so they can be more readily reused between the two. Future PRs will start adding actual "ABIv1" functionality—this is just a bookkeeping PR. ### 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.
1 parent 74a8c52 commit 7493d6e

19 files changed

+88
-71
lines changed

Documentation/ABI/JSON.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ See https://swift.org/CONTRIBUTORS.txt for Swift project authors
1313
This document outlines the JSON schemas used by the testing library for its ABI
1414
entry point and for the `--event-stream-output-path` command-line argument. For
1515
more information about the ABI entry point, see the documentation for
16-
[ABIv0.EntryPoint](https://github.com/search?q=repo%3Aapple%2Fswift-testing%EntryPoint&type=code).
16+
[ABI.v0.EntryPoint](https://github.com/search?q=repo%3Aapple%2Fswift-testing%EntryPoint&type=code).
1717

1818
## Modified Backus-Naur form
1919

Sources/Testing/ABI/v0/ABIv0.Record+Streaming.swift renamed to Sources/Testing/ABI/ABI.Record+Streaming.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//
1010

1111
#if canImport(Foundation) && (!SWT_NO_FILE_IO || !SWT_NO_ABI_ENTRY_POINT)
12-
extension ABIv0.Record {
12+
extension ABI.Record {
1313
/// Post-process encoded JSON and write it to a file.
1414
///
1515
/// - Parameters:

Sources/Testing/ABI/v0/ABIv0.Record.swift renamed to Sources/Testing/ABI/ABI.Record.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
extension ABIv0 {
11+
extension ABI {
1212
/// A type implementing the JSON encoding of records for the ABI entry point
1313
/// and event stream output.
1414
///
@@ -48,7 +48,7 @@ extension ABIv0 {
4848

4949
// MARK: - Codable
5050

51-
extension ABIv0.Record: Codable {
51+
extension ABI.Record: Codable {
5252
private enum CodingKeys: String, CodingKey {
5353
case version
5454
case kind
@@ -73,10 +73,10 @@ extension ABIv0.Record: Codable {
7373
version = try container.decode(Int.self, forKey: .version)
7474
switch try container.decode(String.self, forKey: .kind) {
7575
case "test":
76-
let test = try container.decode(ABIv0.EncodedTest.self, forKey: .payload)
76+
let test = try container.decode(ABI.EncodedTest.self, forKey: .payload)
7777
kind = .test(test)
7878
case "event":
79-
let event = try container.decode(ABIv0.EncodedEvent.self, forKey: .payload)
79+
let event = try container.decode(ABI.EncodedEvent.self, forKey: .payload)
8080
kind = .event(event)
8181
case let kind:
8282
throw DecodingError.dataCorrupted(.init(codingPath: decoder.codingPath, debugDescription: "Unrecognized record kind '\(kind)'"))

Sources/Testing/ABI/ABI.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// This source file is part of the Swift.org open source project
3+
//
4+
// Copyright (c) 2024–2025 Apple Inc. and the Swift project authors
5+
// Licensed under Apache License v2.0 with Runtime Library Exception
6+
//
7+
// See https://swift.org/LICENSE.txt for license information
8+
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
//
10+
11+
/// A namespace for ABI symbols.
12+
@_spi(ForToolsIntegrationOnly)
13+
public enum ABI: Sendable {}
14+
15+
// MARK: -
16+
17+
@_spi(ForToolsIntegrationOnly)
18+
extension ABI {
19+
/// A namespace for ABI version 0 symbols.
20+
public enum v0: Sendable {}
21+
22+
/// A namespace for ABI version 1 symbols.
23+
@_spi(Experimental)
24+
public enum v1: Sendable {}
25+
}
26+
27+
/// A namespace for ABI version 0 symbols.
28+
@_spi(ForToolsIntegrationOnly)
29+
@available(*, deprecated, renamed: "ABI.v0")
30+
public typealias ABIv0 = ABI.v0

Sources/Testing/ABI/v0/Encoded/ABIv0.EncodedAttachment.swift renamed to Sources/Testing/ABI/Encoded/ABI.EncodedAttachment.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
extension ABIv0 {
11+
extension ABI {
1212
/// A type implementing the JSON encoding of ``Attachment`` for the ABI entry
1313
/// point and event stream output.
1414
///
@@ -29,4 +29,4 @@ extension ABIv0 {
2929

3030
// MARK: - Codable
3131

32-
extension ABIv0.EncodedAttachment: Codable {}
32+
extension ABI.EncodedAttachment: Codable {}

Sources/Testing/ABI/v0/Encoded/ABIv0.EncodedBacktrace.swift renamed to Sources/Testing/ABI/Encoded/ABI.EncodedBacktrace.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
extension ABIv0 {
11+
extension ABI {
1212
/// A type implementing the JSON encoding of ``Backtrace`` for the ABI entry
1313
/// point and event stream output.
1414
///
@@ -33,7 +33,7 @@ extension ABIv0 {
3333

3434
// MARK: - Codable
3535

36-
extension ABIv0.EncodedBacktrace: Codable {
36+
extension ABI.EncodedBacktrace: Codable {
3737
func encode(to encoder: any Encoder) throws {
3838
try symbolicatedAddresses.encode(to: encoder)
3939
}

Sources/Testing/ABI/v0/Encoded/ABIv0.EncodedError.swift renamed to Sources/Testing/ABI/Encoded/ABI.EncodedError.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
extension ABIv0 {
11+
extension ABI {
1212
/// A type implementing the JSON encoding of ``Error`` for the ABI entry point
1313
/// and event stream output.
1414
///
@@ -39,7 +39,7 @@ extension ABIv0 {
3939

4040
// MARK: - Error
4141

42-
extension ABIv0.EncodedError: Error {
42+
extension ABI.EncodedError: Error {
4343
var _domain: String {
4444
domain
4545
}
@@ -56,11 +56,11 @@ extension ABIv0.EncodedError: Error {
5656

5757
// MARK: - Codable
5858

59-
extension ABIv0.EncodedError: Codable {}
59+
extension ABI.EncodedError: Codable {}
6060

6161
// MARK: - CustomTestStringConvertible
6262

63-
extension ABIv0.EncodedError: CustomTestStringConvertible {
63+
extension ABI.EncodedError: CustomTestStringConvertible {
6464
var testDescription: String {
6565
description
6666
}

Sources/Testing/ABI/v0/Encoded/ABIv0.EncodedEvent.swift renamed to Sources/Testing/ABI/Encoded/ABI.EncodedEvent.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
extension ABIv0 {
11+
extension ABI {
1212
/// A type implementing the JSON encoding of ``Event`` for the ABI entry point
1313
/// and event stream output.
1414
///
@@ -109,5 +109,5 @@ extension ABIv0 {
109109

110110
// MARK: - Codable
111111

112-
extension ABIv0.EncodedEvent: Codable {}
113-
extension ABIv0.EncodedEvent.Kind: Codable {}
112+
extension ABI.EncodedEvent: Codable {}
113+
extension ABI.EncodedEvent.Kind: Codable {}

Sources/Testing/ABI/v0/Encoded/ABIv0.EncodedInstant.swift renamed to Sources/Testing/ABI/Encoded/ABI.EncodedInstant.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
extension ABIv0 {
11+
extension ABI {
1212
/// A type implementing the JSON encoding of ``Test/Clock/Instant`` for the
1313
/// ABI entry point and event stream output.
1414
///
@@ -37,4 +37,4 @@ extension ABIv0 {
3737

3838
// MARK: - Codable
3939

40-
extension ABIv0.EncodedInstant: Codable {}
40+
extension ABI.EncodedInstant: Codable {}

Sources/Testing/ABI/v0/Encoded/ABIv0.EncodedIssue.swift renamed to Sources/Testing/ABI/Encoded/ABI.EncodedIssue.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
extension ABIv0 {
11+
extension ABI {
1212
/// A type implementing the JSON encoding of ``Issue`` for the ABI entry point
1313
/// and event stream output.
1414
///
@@ -65,5 +65,5 @@ extension ABIv0 {
6565

6666
// MARK: - Codable
6767

68-
extension ABIv0.EncodedIssue: Codable {}
69-
extension ABIv0.EncodedIssue.Severity: Codable {}
68+
extension ABI.EncodedIssue: Codable {}
69+
extension ABI.EncodedIssue.Severity: Codable {}

Sources/Testing/ABI/v0/Encoded/ABIv0.EncodedMessage.swift renamed to Sources/Testing/ABI/Encoded/ABI.EncodedMessage.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
extension ABIv0 {
11+
extension ABI {
1212
/// A type implementing the JSON encoding of
1313
/// ``Event/HumanReadableOutputRecorder/Message`` for the ABI entry point and
1414
/// event stream output.
@@ -76,5 +76,5 @@ extension ABIv0 {
7676

7777
// MARK: - Codable
7878

79-
extension ABIv0.EncodedMessage: Codable {}
80-
extension ABIv0.EncodedMessage.Symbol: Codable {}
79+
extension ABI.EncodedMessage: Codable {}
80+
extension ABI.EncodedMessage.Symbol: Codable {}

Sources/Testing/ABI/v0/Encoded/ABIv0.EncodedTest.swift renamed to Sources/Testing/ABI/Encoded/ABI.EncodedTest.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
extension ABIv0 {
11+
extension ABI {
1212
/// A type implementing the JSON encoding of ``Test`` for the ABI entry point
1313
/// and event stream output.
1414
///
@@ -92,7 +92,7 @@ extension ABIv0 {
9292
}
9393
}
9494

95-
extension ABIv0 {
95+
extension ABI {
9696
/// A type implementing the JSON encoding of ``Test/Case`` for the ABI entry
9797
/// point and event stream output.
9898
///
@@ -120,6 +120,6 @@ extension ABIv0 {
120120

121121
// MARK: - Codable
122122

123-
extension ABIv0.EncodedTest: Codable {}
124-
extension ABIv0.EncodedTest.Kind: Codable {}
125-
extension ABIv0.EncodedTestCase: Codable {}
123+
extension ABI.EncodedTest: Codable {}
124+
extension ABI.EncodedTest.Kind: Codable {}
125+
extension ABI.EncodedTestCase: Codable {}

Sources/Testing/ABI/EntryPoints/ABIEntryPoint.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#if canImport(Foundation) && !SWT_NO_ABI_ENTRY_POINT
1212
private import _TestingInternals
1313

14-
extension ABIv0 {
14+
extension ABI.v0 {
1515
/// The type of the entry point to the testing library used by tools that want
1616
/// to remain version-agnostic regarding the testing library.
1717
///
@@ -62,7 +62,7 @@ extension ABIv0 {
6262
/// untyped pointer.
6363
@_cdecl("swt_abiv0_getEntryPoint")
6464
@usableFromInline func abiv0_getEntryPoint() -> UnsafeRawPointer {
65-
unsafeBitCast(ABIv0.entryPoint, to: UnsafeRawPointer.self)
65+
unsafeBitCast(ABI.v0.entryPoint, to: UnsafeRawPointer.self)
6666
}
6767

6868
#if !SWT_NO_SNAPSHOT_TYPES
@@ -72,7 +72,7 @@ extension ABIv0 {
7272
/// Beta 1.
7373
///
7474
/// This type will be removed in a future update.
75-
@available(*, deprecated, message: "Use ABIv0.EntryPoint instead.")
75+
@available(*, deprecated, message: "Use ABI.v0.EntryPoint instead.")
7676
typealias ABIEntryPoint_v0 = @Sendable (
7777
_ argumentsJSON: UnsafeRawBufferPointer?,
7878
_ recordHandler: @escaping @Sendable (_ recordJSON: UnsafeRawBufferPointer) -> Void
@@ -82,7 +82,7 @@ typealias ABIEntryPoint_v0 = @Sendable (
8282
/// Xcode 16 Beta 1.
8383
///
8484
/// This function will be removed in a future update.
85-
@available(*, deprecated, message: "Use ABIv0.entryPoint (swt_abiv0_getEntryPoint()) instead.")
85+
@available(*, deprecated, message: "Use ABI.v0.entryPoint (swt_abiv0_getEntryPoint()) instead.")
8686
@_cdecl("swt_copyABIEntryPoint_v0")
8787
@usableFromInline func copyABIEntryPoint_v0() -> UnsafeMutableRawPointer {
8888
let result = UnsafeMutablePointer<ABIEntryPoint_v0>.allocate(capacity: 1)
@@ -124,8 +124,8 @@ private func _entryPoint(
124124
let exitCode = await entryPoint(passing: args, eventHandler: eventHandler)
125125

126126
// To maintain compatibility with Xcode 16 Beta 1, suppress custom exit codes.
127-
// (This is also needed by ABIv0.entryPoint to correctly treat the no-tests as
128-
// a successful run.)
127+
// (This is also needed by ABI.v0.entryPoint to correctly treat the no-tests
128+
// as a successful run.)
129129
if exitCode == EXIT_NO_TESTS_FOUND {
130130
return EXIT_SUCCESS
131131
}

Sources/Testing/ABI/EntryPoints/EntryPoint.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,8 +612,8 @@ func eventHandlerForStreamingEvents(
612612
// will be removed in a future update. Do not use it.
613613
eventHandlerForStreamingEventSnapshots(to: eventHandler)
614614
#endif
615-
case nil, 0:
616-
ABIv0.Record.eventHandler(encodeAsJSONLines: encodeAsJSONLines, forwardingTo: eventHandler)
615+
case nil, 0, 1:
616+
ABI.Record.eventHandler(encodeAsJSONLines: encodeAsJSONLines, forwardingTo: eventHandler)
617617
case let .some(unsupportedVersion):
618618
throw _EntryPointError.invalidArgument("--event-stream-version", value: "\(unsupportedVersion)")
619619
}

Sources/Testing/ABI/v0/ABIv0.swift

Lines changed: 0 additions & 13 deletions
This file was deleted.

Sources/Testing/CMakeLists.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ add_library(Testing
1010
ABI/EntryPoints/ABIEntryPoint.swift
1111
ABI/EntryPoints/EntryPoint.swift
1212
ABI/EntryPoints/SwiftPMEntryPoint.swift
13-
ABI/v0/ABIv0.Record.swift
14-
ABI/v0/ABIv0.Record+Streaming.swift
15-
ABI/v0/ABIv0.swift
16-
ABI/v0/Encoded/ABIv0.EncodedAttachment.swift
17-
ABI/v0/Encoded/ABIv0.EncodedBacktrace.swift
18-
ABI/v0/Encoded/ABIv0.EncodedError.swift
19-
ABI/v0/Encoded/ABIv0.EncodedEvent.swift
20-
ABI/v0/Encoded/ABIv0.EncodedInstant.swift
21-
ABI/v0/Encoded/ABIv0.EncodedIssue.swift
22-
ABI/v0/Encoded/ABIv0.EncodedMessage.swift
23-
ABI/v0/Encoded/ABIv0.EncodedTest.swift
13+
ABI/ABI.Record.swift
14+
ABI/ABI.Record+Streaming.swift
15+
ABI/ABI.swift
16+
ABI/Encoded/ABI.EncodedAttachment.swift
17+
ABI/Encoded/ABI.EncodedBacktrace.swift
18+
ABI/Encoded/ABI.EncodedError.swift
19+
ABI/Encoded/ABI.EncodedEvent.swift
20+
ABI/Encoded/ABI.EncodedInstant.swift
21+
ABI/Encoded/ABI.EncodedIssue.swift
22+
ABI/Encoded/ABI.EncodedMessage.swift
23+
ABI/Encoded/ABI.EncodedTest.swift
2424
Attachments/Attachable.swift
2525
Attachments/AttachableContainer.swift
2626
Attachments/Attachment.swift

Sources/Testing/ExitTests/ExitTest.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ extension ExitTest {
444444
// Encode events as JSON and write them to the back channel file handle.
445445
// Only forward issue-recorded events. (If we start handling other kinds of
446446
// events in the future, we can forward them too.)
447-
let eventHandler = ABIv0.Record.eventHandler(encodeAsJSONLines: true) { json in
447+
let eventHandler = ABI.Record.eventHandler(encodeAsJSONLines: true) { json in
448448
_ = try? _backChannelForEntryPoint?.withLock {
449449
try _backChannelForEntryPoint?.write(json)
450450
try _backChannelForEntryPoint?.write("\n")
@@ -692,7 +692,7 @@ extension ExitTest {
692692
///
693693
/// - Throws: Any error encountered attempting to decode or process the JSON.
694694
private static func _processRecord(_ recordJSON: UnsafeRawBufferPointer, fromBackChannel backChannel: borrowing FileHandle) throws {
695-
let record = try JSON.decode(ABIv0.Record.self, from: recordJSON)
695+
let record = try JSON.decode(ABI.Record.self, from: recordJSON)
696696

697697
if case let .event(event) = record.kind, let issue = event.issue {
698698
// Translate the issue back into a "real" issue and record it

0 commit comments

Comments
 (0)