@@ -149,17 +149,21 @@ extension Runner {
149
149
///
150
150
/// - Parameters:
151
151
/// - sequence: The sequence to enumerate.
152
+ /// - taskNamer: A function to invoke for each element in `sequence`. The
153
+ /// result of this function is used to name each child task.
152
154
/// - body: The function to invoke.
153
155
///
154
156
/// - Throws: Whatever is thrown by `body`.
155
157
private static func _forEach< E> (
156
158
in sequence: some Sequence < E > ,
157
- _ body: @Sendable @escaping ( E) async throws -> Void
159
+ namingTasksWith taskNamer: ( borrowing E ) -> ( taskName: String , action: String ? ) ? ,
160
+ _ body: @Sendable @escaping ( borrowing E ) async throws -> Void
158
161
) async rethrows where E: Sendable {
159
162
try await withThrowingTaskGroup { taskGroup in
160
163
for element in sequence {
161
164
// Each element gets its own subtask to run in.
162
- taskGroup. addTask {
165
+ let taskName = taskNamer ( element)
166
+ taskGroup. addTask ( name: decorateTaskName ( taskName? . taskName, withAction: taskName? . action) ) {
163
167
try await body ( element)
164
168
}
165
169
@@ -314,8 +318,19 @@ extension Runner {
314
318
}
315
319
}
316
320
321
+ // Figure out how to name child tasks.
322
+ func taskNamer( _ childGraph: Graph < String , Plan . Step ? > ) -> ( String , String ? ) ? {
323
+ childGraph. value. map { step in
324
+ let testName = step. test. humanReadableName ( )
325
+ if step. test. isSuite {
326
+ return ( " suite \( testName) " , " running " )
327
+ }
328
+ return ( " test \( testName) " , nil ) // test cases have " - running" suffix
329
+ }
330
+ }
331
+
317
332
// Run the child nodes.
318
- try await _forEach ( in: childGraphs) { _ , childGraph in
333
+ try await _forEach ( in: childGraphs. lazy . map ( \ . value ) , namingTasksWith : taskNamer ) { childGraph in
319
334
try await _runStep ( atRootOf: childGraph)
320
335
}
321
336
}
@@ -335,7 +350,15 @@ extension Runner {
335
350
testCaseFilter ( testCase, step. test)
336
351
}
337
352
338
- await _forEach ( in: testCases) { testCase in
353
+ // Figure out how to name child tasks.
354
+ let testName = " test \( step. test. humanReadableName ( ) ) "
355
+ let taskNamer : ( Int , Test . Case ) -> ( String , String ? ) ? = if step. test. isParameterized {
356
+ { i, _ in ( testName, " running test case # \( i + 1 ) " ) }
357
+ } else {
358
+ { _, _ in ( testName, " running " ) }
359
+ }
360
+
361
+ await _forEach ( in: testCases. enumerated ( ) , namingTasksWith: taskNamer) { _, testCase in
339
362
await _runTestCase ( testCase, within: step)
340
363
}
341
364
}
@@ -418,14 +441,19 @@ extension Runner {
418
441
}
419
442
420
443
let repetitionPolicy = runner. configuration. repetitionPolicy
421
- for iterationIndex in 0 ..< repetitionPolicy. maximumIterationCount {
444
+ let iterationCount = repetitionPolicy. maximumIterationCount
445
+ for iterationIndex in 0 ..< iterationCount {
422
446
Event . post ( . iterationStarted( iterationIndex) , for: ( nil , nil ) , configuration: runner. configuration)
423
447
defer {
424
448
Event . post ( . iterationEnded( iterationIndex) , for: ( nil , nil ) , configuration: runner. configuration)
425
449
}
426
450
427
451
await withTaskGroup { [ runner] taskGroup in
428
- _ = taskGroup. addTaskUnlessCancelled {
452
+ var taskAction : String ?
453
+ if iterationCount > 1 {
454
+ taskAction = " running iteration # \( iterationIndex + 1 ) "
455
+ }
456
+ _ = taskGroup. addTaskUnlessCancelled ( name: decorateTaskName ( " test run " , withAction: taskAction) ) {
429
457
try ? await _runStep ( atRootOf: runner. plan. stepGraph)
430
458
}
431
459
await taskGroup. waitForAll ( )
0 commit comments