Skip to content

Commit 944d9e6

Browse files
authored
Lower more experimental JSON fields. (#1301)
This PR suppresses more experimental JSON fields if they aren't supposed to be included in the current JSON event stream version: - All experimental event kinds. - Attachments' preferred names and bytes/contents. - Hoisted comments and source locations for all event kinds. ### 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 c169ca3 commit 944d9e6

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

Sources/Testing/ABI/ABI.Record.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ extension ABI {
3636
guard let event = EncodedEvent<V>(encoding: event, in: eventContext, messages: messages) else {
3737
return nil
3838
}
39+
if !V.includesExperimentalFields && event.kind.rawValue.first == "_" {
40+
// Don't encode experimental event kinds.
41+
return nil
42+
}
3943
kind = .event(event)
4044
}
4145
}

Sources/Testing/ABI/Encoded/ABI.EncodedAttachment.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ extension ABI {
4141
init(encoding attachment: borrowing Attachment<AnyAttachable>, in eventContext: borrowing Event.Context) {
4242
path = attachment.fileSystemPath
4343

44-
if V.versionNumber >= ABI.v6_3.versionNumber {
44+
if V.includesExperimentalFields {
4545
_preferredName = attachment.preferredName
4646

4747
if path == nil {

Sources/Testing/ABI/Encoded/ABI.EncodedEvent.swift

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,31 +112,22 @@ extension ABI {
112112
case let .issueRecorded(recordedIssue):
113113
kind = .issueRecorded
114114
issue = EncodedIssue(encoding: recordedIssue, in: eventContext)
115-
_comments = recordedIssue.comments.map(\.rawValue)
116-
_sourceLocation = recordedIssue.sourceLocation
117115
case let .valueAttached(attachment):
118116
kind = .valueAttached
119117
self.attachment = EncodedAttachment(encoding: attachment, in: eventContext)
120-
_sourceLocation = attachment.sourceLocation
121118
case .testCaseEnded:
122119
if eventContext.test?.isParameterized == false {
123120
return nil
124121
}
125122
kind = .testCaseEnded
126-
case let .testCaseCancelled(skipInfo):
123+
case .testCaseCancelled:
127124
kind = .testCaseCancelled
128-
_comments = Array(skipInfo.comment).map(\.rawValue)
129-
_sourceLocation = skipInfo.sourceLocation
130125
case .testEnded:
131126
kind = .testEnded
132-
case let .testSkipped(skipInfo):
127+
case .testSkipped:
133128
kind = .testSkipped
134-
_comments = Array(skipInfo.comment).map(\.rawValue)
135-
_sourceLocation = skipInfo.sourceLocation
136-
case let .testCancelled(skipInfo):
129+
case .testCancelled:
137130
kind = .testCancelled
138-
_comments = Array(skipInfo.comment).map(\.rawValue)
139-
_sourceLocation = skipInfo.sourceLocation
140131
case .runEnded:
141132
kind = .runEnded
142133
default:
@@ -148,6 +139,21 @@ extension ABI {
148139

149140
// Experimental fields
150141
if V.includesExperimentalFields {
142+
switch event.kind {
143+
case let .issueRecorded(recordedIssue):
144+
_comments = recordedIssue.comments.map(\.rawValue)
145+
_sourceLocation = recordedIssue.sourceLocation
146+
case let .valueAttached(attachment):
147+
_sourceLocation = attachment.sourceLocation
148+
case let .testCaseCancelled(skipInfo),
149+
let .testSkipped(skipInfo),
150+
let .testCancelled(skipInfo):
151+
_comments = Array(skipInfo.comment).map(\.rawValue)
152+
_sourceLocation = skipInfo.sourceLocation
153+
default:
154+
break
155+
}
156+
151157
if eventContext.test?.isParameterized == true {
152158
_testCase = eventContext.testCase.map(EncodedTestCase.init)
153159
}

0 commit comments

Comments
 (0)