Skip to content

Commit e311001

Browse files
committed
Review feedback
1 parent cfa472f commit e311001

7 files changed

Lines changed: 21 additions & 21 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ extension ABI {
117117
case .testStarted:
118118
kind = .testStarted
119119
case .testCaseStarted:
120+
// For non-parameterized tests, we elide `testCaseStarted` calls because it would be
121+
// redundant. However, for multiple iterations of a test case within a non-parameterized
122+
// function, we need to emit another `testStarted` event.
120123
if eventContext.test?.isParameterized == false {
121124
if let iteration = eventContext.iteration, iteration > 1 {
122125
kind = .testStarted

Sources/Testing/ABI/EntryPoints/EntryPoint.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ public struct __CommandLineArguments_v0: Sendable {
333333
/// The value of the `--repeat-until` argument.
334334
public var repeatUntil: String?
335335

336+
/// Whether or not to use the per-test-case repetition mode.
336337
var usePerTestCaseRepetition: Bool = false
337338

338339
/// The value of the `--attachments-path` argument.

Sources/Testing/Events/Recorder/Event.HumanReadableOutputRecorder.swift

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -572,16 +572,13 @@ extension Event.HumanReadableOutputRecorder {
572572
guard let test, let testCase else { break }
573573
let iteration = eventContext.iteration ?? 1
574574

575-
let shouldShowMessage = testCase.isParameterized || iteration > 1
576-
577-
guard shouldShowMessage else {
578-
break
579-
}
580-
581-
var message = if testCase.isParameterized, let arguments = testCase.arguments {
582-
"Test case passing \(arguments.count.counting("argument")) \(testCase.labeledArguments(includingQualifiedTypeNames: verbosity > 0)) to \(testName) started"
575+
var message: String
576+
if testCase.isParameterized, let arguments = testCase.arguments {
577+
message = "Test case passing \(arguments.count.counting("argument")) \(testCase.labeledArguments(includingQualifiedTypeNames: verbosity > 0)) to \(testName) started"
578+
} else if iteration > 1 {
579+
message = testStartedMessage(for: test)
583580
} else {
584-
testStartedMessage(for: test)
581+
break
585582
}
586583

587584
if iteration > 1 {

Sources/Testing/Running/Configuration.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ public struct Configuration: Sendable {
134134

135135
/// Whether to perform test repetition at the plan level or on a per-test-
136136
/// case basis.
137+
@_spi(Experimental)
137138
public var shouldUseLegacyPlanLevelRepetition: Bool = true
138139

139140
/// Whether or not, and how, to iterate the test plan repeatedly.

Sources/Testing/Running/Runner.RuntimeState.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ extension Runner {
2929
/// The test case that is running on the current task, if any.
3030
var testCase: Test.Case?
3131

32-
/// The current iteration of the test repetition policy.
32+
/// The current iteration of the test repetition policy, if any.
3333
var iteration: Int?
3434

3535
/// The runtime state related to the runner running on the current task,
@@ -201,7 +201,7 @@ extension Configuration {
201201
}
202202
}
203203

204-
// MARK: - Current test and test case
204+
// MARK: - Current test, test case, and iteration
205205

206206
extension Test {
207207
/// The test that is running on the current task, if any.
@@ -237,6 +237,7 @@ extension Test {
237237
}
238238
}
239239

240+
/// The current iteration of the currently-running test case, if any.
240241
static var currentIteration: Int? {
241242
Runner.RuntimeState.current?.iteration
242243
}

Sources/Testing/Running/Runner.swift

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -385,9 +385,9 @@ extension Runner {
385385
if let testCaseSerializer = context.testCaseSerializer {
386386
// Note that if .serialized is applied to an inner scope, we still use
387387
// this serializer (if set) so that we don't overcommit.
388-
await testCaseSerializer.run { await _runTestCase(testCase, within: step, context: context) }
388+
await testCaseSerializer.run { await _runTestCase(testCase, within: step) }
389389
} else {
390-
await _runTestCase(testCase, within: step, context: context)
390+
await _runTestCase(testCase, within: step)
391391
}
392392
}
393393
}
@@ -402,8 +402,7 @@ extension Runner {
402402
/// body closure.
403403
private static func _runTestCase(
404404
_ testCase: Test.Case,
405-
within step: Plan.Step,
406-
context: _Context
405+
within step: Plan.Step
407406
) async {
408407
if _configuration.shouldUseLegacyPlanLevelRepetition {
409408
await _runSingleTestCaseIteration(testCase, within: step)
@@ -456,8 +455,6 @@ extension Runner {
456455
/// repeatedly until the continuation condition is satisfied.
457456
///
458457
/// - Parameters:
459-
/// - test: The test being executed.
460-
/// - testCase: The test case being iterated.
461458
/// - body: The actual body of the function which must ultimately call into the test function.
462459
///
463460
/// - Note: This function updates ``Configuration/current`` before invoking the test body.
@@ -554,15 +551,15 @@ extension Runner {
554551
defer {
555552
Event.post(.iterationEnded(iterationIndex), configuration: runner.configuration)
556553
}
557-
await runner.runAll(context: context)
554+
await runner._runAllTests(context: context)
558555
}
559556
} else {
560-
await runner.runAll(context: context)
557+
await runner._runAllTests(context: context)
561558
}
562559
}
563560
}
564561

565-
private func runAll(context: _Context) async {
562+
private func _runAllTests(context: _Context) async {
566563
await withTaskGroup { taskGroup in
567564
_ = taskGroup.addTaskUnlessCancelled(name: decorateTaskName("test run", withAction: nil)) {
568565
try? await Self._runStep(atRootOf: plan.stepGraph, context: context)

Tests/TestingTests/TestCaseIterationTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// This source file is part of the Swift.org open source project
33
//
4-
// Copyright (c) 2024 Apple Inc. and the Swift project authors
4+
// Copyright (c) 2026 Apple Inc. and the Swift project authors
55
// Licensed under Apache License v2.0 with Runtime Library Exception
66
//
77
// See https://swift.org/LICENSE.txt for license information

0 commit comments

Comments
 (0)