@@ -149,17 +149,21 @@ extension Runner {
149149 ///
150150 /// - Parameters:
151151 /// - 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.
152154 /// - body: The function to invoke.
153155 ///
154156 /// - Throws: Whatever is thrown by `body`.
155157 private static func _forEach< E> (
156158 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
158161 ) async rethrows where E: Sendable {
159162 try await withThrowingTaskGroup { taskGroup in
160163 for element in sequence {
161164 // 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) ) {
163167 try await body ( element)
164168 }
165169
@@ -314,8 +318,19 @@ extension Runner {
314318 }
315319 }
316320
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+
317332 // 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
319334 try await _runStep ( atRootOf: childGraph)
320335 }
321336 }
@@ -335,7 +350,15 @@ extension Runner {
335350 testCaseFilter ( testCase, step. test)
336351 }
337352
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
339362 await _runTestCase ( testCase, within: step)
340363 }
341364 }
@@ -418,14 +441,19 @@ extension Runner {
418441 }
419442
420443 let repetitionPolicy = runner. configuration. repetitionPolicy
421- for iterationIndex in 0 ..< repetitionPolicy. maximumIterationCount {
444+ let iterationCount = repetitionPolicy. maximumIterationCount
445+ for iterationIndex in 0 ..< iterationCount {
422446 Event . post ( . iterationStarted( iterationIndex) , for: ( nil , nil ) , configuration: runner. configuration)
423447 defer {
424448 Event . post ( . iterationEnded( iterationIndex) , for: ( nil , nil ) , configuration: runner. configuration)
425449 }
426450
427451 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) ) {
429457 try ? await _runStep ( atRootOf: runner. plan. stepGraph)
430458 }
431459 await taskGroup. waitForAll ( )
0 commit comments