Skip to content

Commit 4041630

Browse files
authored
Add swift test --no-parallel (#7231)
This PR makes the `--parallel` flag on the swift-test subtool invertible with a "no" prefix. We want swift-testing to default to enabling parallelization, but we don't want to break XCTest (which for historical reasons strongly prefers serial testing.) Deprecating `--parallel` and replacing it with `--{enable,disable}-parallelism` or similar seems a bit heavy-handed. Swift Argument Parser gives us the option to use a "no" prefix instead which means that the existing `--parallel` option will continue to work as intended. Support for `--no-parallel` in swift-testing is here: swiftlang/swift-testing#174
1 parent 8ff74e3 commit 4041630

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Sources/Commands/SwiftTestTool.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ struct TestToolOptions: ParsableArguments {
122122

123123
/// If tests should run in parallel mode.
124124
@Flag(name: .customLong("parallel"),
125+
inversion: .prefixedNo,
125126
help: "Run the tests in parallel.")
126127
var shouldRunInParallel: Bool = false
127128

@@ -553,7 +554,9 @@ public struct SwiftTestTool: SwiftCommand {
553554
// Validation for --num-workers.
554555
if let workers = options.numberOfWorkers {
555556

556-
// The --num-worker option should be called with --parallel.
557+
// The --num-worker option should be called with --parallel. Since
558+
// this option does not affect swift-testing at this time, we can
559+
// effectively ignore that it defaults to enabling parallelization.
557560
guard options.shouldRunInParallel else {
558561
throw StringError("--num-workers must be used with --parallel")
559562
}

Tests/CommandsTests/TestToolTests.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ final class TestToolTests: CommandsTestCase {
9292
XCTAssertThrowsCommandExecutionError(try SwiftPM.Test.execute(packagePath: fixturePath)) { error in
9393
// in "swift test" test output goes to stdout
9494
XCTAssertMatch(error.stdout, .contains("Executed 2 tests"))
95+
XCTAssertNoMatch(error.stdout, .contains("[3/3]"))
96+
}
97+
98+
// Try --no-parallel.
99+
XCTAssertThrowsCommandExecutionError(try SwiftPM.Test.execute(["--no-parallel"], packagePath: fixturePath)) { error in
100+
// in "swift test" test output goes to stdout
101+
XCTAssertMatch(error.stdout, .contains("Executed 2 tests"))
102+
XCTAssertNoMatch(error.stdout, .contains("[3/3]"))
95103
}
96104

97105
// Run tests in parallel.

0 commit comments

Comments
 (0)