Skip to content

Commit 8b09896

Browse files
committed
Adapt to the iteration parameter in the event context
1 parent 28f016c commit 8b09896

File tree

4 files changed

+31
-28
lines changed

4 files changed

+31
-28
lines changed

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,14 @@ extension ABI {
113113
kind = .testStarted
114114
case .testCaseStarted:
115115
if eventContext.test?.isParameterized == false {
116-
return nil
116+
if let iteration = eventContext.iteration, iteration > 1 {
117+
kind = .testStarted
118+
} else {
119+
return nil
120+
}
121+
} else {
122+
kind = .testCaseStarted
117123
}
118-
kind = .testCaseStarted
119124
case let .issueRecorded(recordedIssue):
120125
kind = .issueRecorded
121126
issue = EncodedIssue(encoding: recordedIssue, in: eventContext)
@@ -124,9 +129,14 @@ extension ABI {
124129
self.attachment = EncodedAttachment(encoding: attachment, in: eventContext)
125130
case .testCaseEnded:
126131
if eventContext.test?.isParameterized == false {
127-
return nil
132+
if let iteration = eventContext.iteration, iteration > 1 {
133+
kind = .testEnded
134+
} else {
135+
return nil
136+
}
137+
} else {
138+
kind = .testCaseEnded
128139
}
129-
kind = .testCaseEnded
130140
case .testCaseCancelled:
131141
kind = .testCaseCancelled
132142
case .testEnded:
@@ -159,6 +169,7 @@ extension ABI {
159169
let .testCancelled(skipInfo):
160170
_comments = Array(skipInfo.comment).map(\.rawValue)
161171
_sourceLocation = skipInfo.sourceLocation.map { EncodedSourceLocation(encoding: $0) }
172+
_iteration = eventContext.iteration
162173
default:
163174
break
164175
}

Sources/Testing/Running/Runner.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,10 @@ extension Runner {
227227
// Determine what kind of event to send for this step based on its action.
228228
switch step.action {
229229
case .run:
230-
Event.post(.testStarted, for: (step.test, nil), iteration: context.iteration, configuration: configuration)
230+
Event.post(.testStarted, for: (step.test, nil), iteration: 1, configuration: configuration)
231231
shouldSendTestEnded = true
232232
case let .skip(skipInfo):
233-
Event.post(.testSkipped(skipInfo), for: (step.test, nil), iteration: context.iteration, configuration: configuration)
233+
Event.post(.testSkipped(skipInfo), for: (step.test, nil), iteration: 1, configuration: configuration)
234234
shouldSendTestEnded = false
235235
case let .recordIssue(issue):
236236
// Scope posting the issue recorded event such that issue handling
@@ -254,7 +254,7 @@ extension Runner {
254254
defer {
255255
if let step = stepGraph.value {
256256
if shouldSendTestEnded {
257-
Event.post(.testEnded, for: (step.test, nil), iteration: context.iteration, configuration: configuration)
257+
Event.post(.testEnded, for: (step.test, nil), iteration: 1, configuration: configuration)
258258
}
259259
Event.post(.planStepEnded(step), for: (step.test, nil), configuration: configuration)
260260
}

Tests/TestingTests/EventIterationTests.swift

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,6 @@ struct EventIterationTests {
6060
}
6161
}
6262

63-
@Test
64-
func `testStarted and testEnded events include iteration in context`() async {
65-
await verifyIterations(
66-
for: [.testStarted, .testEnded],
67-
repetitionPolicy: .once,
68-
expectedIterations: 1
69-
) { _ in
70-
// Do nothing, just pass
71-
}
72-
}
73-
7463
@Test
7564
func `testCaseStarted and testCaseEnded events include iteration in context`() async {
7665
await verifyIterations(

Tests/TestingTests/PlanIterationTests.swift

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ struct TestCaseIterationTests {
2222
await confirmation("1 iteration ended") { ended in
2323
var configuration = Configuration()
2424
configuration.eventHandler = { event, _ in
25-
if case .testStarted = event.kind {
25+
if case .testCaseStarted = event.kind {
2626
started()
27-
} else if case .testEnded = event.kind {
27+
} else if case .testCaseEnded = event.kind {
2828
ended()
2929
}
3030
}
@@ -43,9 +43,9 @@ struct TestCaseIterationTests {
4343
await confirmation("N iterations ended", expectedCount: iterationCount) { ended in
4444
var configuration = Configuration()
4545
configuration.eventHandler = { event, _ in
46-
if case .testStarted = event.kind {
46+
if case .testCaseStarted = event.kind {
4747
started()
48-
} else if case .testEnded = event.kind {
48+
} else if case .testCaseEnded = event.kind {
4949
ended()
5050
}
5151
}
@@ -70,17 +70,17 @@ struct TestCaseIterationTests {
7070
var configuration = Configuration()
7171
configuration.eventHandler = { event, context in
7272
guard let iteration = context.iteration else { return }
73-
if case .testStarted = event.kind {
73+
if case .testCaseStarted = event.kind {
7474
iterations.withLock { $0 = iteration }
7575
started()
76-
} else if case .testEnded = event.kind {
76+
} else if case .testCaseEnded = event.kind {
7777
ended()
7878
}
7979
}
8080
configuration.repetitionPolicy = .repeating(.untilIssueRecorded, maximumIterationCount: iterationCount)
8181

8282
await Test {
83-
#expect(iterations.rawValue < iterationWithIssue)
83+
#expect(iterations.rawValue <= iterationWithIssue)
8484
}.run(configuration: configuration)
8585
}
8686
}
@@ -96,10 +96,10 @@ struct TestCaseIterationTests {
9696
var configuration = Configuration()
9797
configuration.eventHandler = { event, context in
9898
guard let iteration = context.iteration else { return }
99-
if case .testStarted = event.kind {
99+
if case .testCaseStarted = event.kind {
100100
iterations.withLock { $0 = iteration }
101101
started()
102-
} else if case .testEnded = event.kind {
102+
} else if case .testCaseEnded = event.kind {
103103
ended()
104104
}
105105
}
@@ -122,7 +122,10 @@ struct TestCaseIterationTests {
122122

123123
var configuration = Configuration()
124124
configuration.eventHandler = { event, context in
125-
guard let test = context.test, let iteration = context.iteration else { return }
125+
guard case .testCaseStarted = event.kind,
126+
let test = context.test,
127+
let iteration = context.iteration
128+
else { return }
126129
if test.name.contains("Failing") {
127130
iterationForFailingTest.withLock { $0 = iteration }
128131
}

0 commit comments

Comments
 (0)