Skip to content

Commit 6bcece8

Browse files
committed
Opt repetition event handlers out of being considered for all
1 parent a9f0a15 commit 6bcece8

2 files changed

Lines changed: 24 additions & 10 deletions

File tree

Sources/Testing/Running/Runner.RuntimeState.swift

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,22 @@ extension Configuration {
7474
///
7575
/// - Parameters:
7676
/// - configuration: The new value to set for ``Configuration/current``.
77+
/// - addingToAll: Whether to add this configuration to the set of implicitly-tracked ``Configuration``s that are told about detached Issues.
7778
/// - body: A function to call.
7879
///
7980
/// - Returns: Whatever is returned by `body`.
8081
///
8182
/// - Throws: Whatever is thrown by `body`.
82-
static func withCurrent<R>(_ configuration: Self, perform body: () throws -> R) rethrows -> R {
83-
let id = configuration._addToAll()
83+
static func withCurrent<R>(
84+
_ configuration: Self,
85+
addingToAll: Bool = true,
86+
perform body: () throws -> R
87+
) rethrows -> R {
88+
let id = addingToAll ? configuration._addToAll() : nil
8489
defer {
85-
configuration._removeFromAll(identifiedBy: id)
90+
if let id {
91+
configuration._removeFromAll(identifiedBy: id)
92+
}
8693
}
8794

8895
var runtimeState = Runner.RuntimeState.current ?? .init()
@@ -95,15 +102,22 @@ extension Configuration {
95102
///
96103
/// - Parameters:
97104
/// - configuration: The new value to set for ``Configuration/current``.
105+
/// - addingToAll: Whether to add this configuration to the set of implicitly-tracked ``Configuration``s that are told about detached Issues.
98106
/// - body: A function to call.
99107
///
100108
/// - Returns: Whatever is returned by `body`.
101109
///
102110
/// - Throws: Whatever is thrown by `body`.
103-
static func withCurrent<R>(_ configuration: Self, perform body: () async throws -> R) async rethrows -> R {
104-
let id = configuration._addToAll()
111+
static func withCurrent<R>(
112+
_ configuration: Self,
113+
addingToAll: Bool = true,
114+
perform body: () async throws -> R
115+
) async rethrows -> R {
116+
let id = addingToAll ? configuration._addToAll() : nil
105117
defer {
106-
configuration._removeFromAll(identifiedBy: id)
118+
if let id {
119+
configuration._removeFromAll(identifiedBy: id)
120+
}
107121
}
108122

109123
var runtimeState = Runner.RuntimeState.current ?? .init()

Sources/Testing/Running/Runner.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,10 @@ extension Runner {
226226
// Determine what kind of event to send for this step based on its action.
227227
switch step.action {
228228
case .run:
229-
Event.post(.testStarted, for: (step.test, nil), iteration: context.iteration, configuration: configuration)
229+
Event.post(.testStarted, for: (step.test, nil), configuration: configuration)
230230
shouldSendTestEnded = true
231231
case let .skip(skipInfo):
232-
Event.post(.testSkipped(skipInfo), for: (step.test, nil), iteration: context.iteration, configuration: configuration)
232+
Event.post(.testSkipped(skipInfo), for: (step.test, nil), configuration: configuration)
233233
shouldSendTestEnded = false
234234
case let .recordIssue(issue):
235235
// Scope posting the issue recorded event such that issue handling
@@ -247,7 +247,7 @@ extension Runner {
247247
}
248248
defer {
249249
if shouldSendTestEnded {
250-
Event.post(.testEnded, for: (step.test, nil), iteration: context.iteration, configuration: configuration)
250+
Event.post(.testEnded, for: (step.test, nil), configuration: configuration)
251251
}
252252
}
253253

@@ -506,7 +506,7 @@ extension Runner {
506506
}
507507

508508
await Test.withCurrentIteration(iteration) {
509-
await Configuration.withCurrent(config) {
509+
await Configuration.withCurrent(config, addingToAll: false) {
510510
await body()
511511
}
512512
}

0 commit comments

Comments
 (0)