Skip to content

Commit cfa472f

Browse files
committed
Add CLI flag to opt in to new test repetition mode
1 parent 44b2f90 commit cfa472f

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

Sources/Testing/ABI/EntryPoints/EntryPoint.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,6 @@ func entryPoint(passing args: __CommandLineArguments_v0?, eventHandler: Event.Ha
8383
}
8484
#endif
8585

86-
// If the client has requested repetitions via CLI flags, turn off plan-level repetition
87-
// and use test-case-level repetition instead.
88-
if args.repetitions != nil || args.repeatUntil != nil {
89-
configuration.shouldUseLegacyPlanLevelRepetition = false
90-
}
91-
9286
// If the caller specified an alternate event handler, hook it up too.
9387
if let eventHandler {
9488
configuration.eventHandler = { [oldEventHandler = configuration.eventHandler] event, context in
@@ -339,6 +333,8 @@ public struct __CommandLineArguments_v0: Sendable {
339333
/// The value of the `--repeat-until` argument.
340334
public var repeatUntil: String?
341335

336+
var usePerTestCaseRepetition: Bool = false
337+
342338
/// The value of the `--attachments-path` argument.
343339
public var attachmentsPath: String?
344340
}
@@ -543,6 +539,9 @@ func parseCommandLineArguments(from args: [String]) throws -> __CommandLineArgum
543539
if let repeatUntil = args.argumentValue(forLabel: "--repeat-until") {
544540
result.repeatUntil = repeatUntil
545541
}
542+
if args.contains("--experimental-per-test-case-repetition") {
543+
result.usePerTestCaseRepetition = true
544+
}
546545

547546
return result
548547
}
@@ -671,6 +670,9 @@ public func configurationForEntryPoint(from args: __CommandLineArguments_v0) thr
671670
}
672671
configuration.repetitionPolicy = repetitionPolicy
673672

673+
// Opt in to per-test-case repetition
674+
configuration.shouldUseLegacyPlanLevelRepetition = !args.usePerTestCaseRepetition
675+
674676
#if !SWT_NO_EXIT_TESTS
675677
// Enable exit test handling via __swiftPMEntryPoint().
676678
configuration.exitTestHandler = ExitTest.handlerForEntryPoint()

Tests/TestingTests/SwiftPMTests.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,15 @@ struct SwiftPMTests {
511511
#expect(configuration.repetitionPolicy.continuationCondition == .whileIssueRecorded)
512512
}
513513

514+
@Test("--experimental-per-test-case-repetition")
515+
func experimentalPerTestCaseRepetition() throws {
516+
let defaultConfig = try configurationForEntryPoint(withArguments: ["PATH"])
517+
#expect(defaultConfig.shouldUseLegacyPlanLevelRepetition)
518+
519+
let configuration = try configurationForEntryPoint(withArguments: ["PATH", "--experimental-per-test-case-repetition"])
520+
#expect(!configuration.shouldUseLegacyPlanLevelRepetition)
521+
}
522+
514523
@Test("list subcommand")
515524
func list() async throws {
516525
do {

0 commit comments

Comments
 (0)