Skip to content

Commit b85e9a1

Browse files
authored
Fix .testStarted etc. events being suppressed for suites. (#1804)
This fixes events in the JSON event stream not being emitted for test suites. The logic for detecting non-parameterized test (function)s is incorrect and does not account for them. Caused by #1793. ### 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 66bd926 commit b85e9a1

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,35 +67,38 @@ extension ABI {
6767
/// `testStarted`/`testEnded` events, and replace `testCaseStarted`/
6868
/// `testCaseEnded` with `testStarted`/`testEnded`.
6969
/// - For parameterized tests, emit all events.
70-
let isNonParameterizedTest = eventContext.test?.isParameterized == false
70+
var isNonParameterizedTestFunction = false
71+
if let test = eventContext.test, !test.isSuite {
72+
isNonParameterizedTestFunction = !test.isParameterized
73+
}
7174

7275
switch kind {
7376
case .runStarted:
7477
self = .runStarted
7578
case .testStarted:
76-
if isNonParameterizedTest {
79+
if isNonParameterizedTestFunction {
7780
return nil
7881
}
7982
self = .testStarted
8083
case .testCaseStarted:
81-
self = isNonParameterizedTest ? .testStarted : .testCaseStarted
84+
self = isNonParameterizedTestFunction ? .testStarted : .testCaseStarted
8285
case .issueRecorded:
8386
self = .issueRecorded
8487
case .valueAttached:
8588
self = .valueAttached
8689
case .testCaseEnded:
87-
self = isNonParameterizedTest ? .testEnded : .testCaseEnded
90+
self = isNonParameterizedTestFunction ? .testEnded : .testCaseEnded
8891
case .testCaseCancelled:
89-
self = isNonParameterizedTest ? .testCancelled : .testCaseCancelled
92+
self = isNonParameterizedTestFunction ? .testCancelled : .testCaseCancelled
9093
case .testEnded:
91-
if isNonParameterizedTest {
94+
if isNonParameterizedTestFunction {
9295
return nil
9396
}
9497
self = .testEnded
9598
case .testSkipped:
9699
self = .testSkipped
97100
case .testCancelled:
98-
if isNonParameterizedTest {
101+
if isNonParameterizedTestFunction {
99102
return nil
100103
}
101104
self = .testCancelled

Tests/TestingTests/ABI.EncodedTestTests.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,13 @@
9696

9797
#expect(test.decodeIDComponents() == nil)
9898
}
99+
100+
@Test func `Can encode an event for a test suite`() {
101+
let test = Test(traits: [], sourceLocation: .__here(), containingTypeInfo: TypeInfo(describing: Int.self))
102+
let event = Event(.testStarted, testID: test.id, testCaseID: nil)
103+
let eventContext = Event.Context(test: test, testCase: nil, iteration: 1, configuration: nil)
104+
let encodedEvent = ABI.EncodedEvent<ABI.CurrentVersion>(encoding: event, in: eventContext, messages: [])
105+
#expect(encodedEvent != nil)
106+
}
99107
}
100108
#endif

0 commit comments

Comments
 (0)