From 0964deb89bcb9c56c121106eafe19303bf6df242 Mon Sep 17 00:00:00 2001 From: Paul LeMarquand Date: Wed, 10 Sep 2025 15:20:41 -0400 Subject: [PATCH 1/7] Test: Consolidate expectThrowsCommandExecutionError usage - Add throwing and non-throwing overloads for expectThrowsCommandExecutionError in SwiftTesting+Helpers - Remove duplicate implementation from APIDiffTests - Simplify call sites by using appropriate overload without unnecessary `try`s where appropriate --- .../SwiftTesting+Helpers.swift | 66 ++++++++++++------- Tests/CommandsTests/APIDiffTests.swift | 45 ++++--------- 2 files changed, 56 insertions(+), 55 deletions(-) diff --git a/Sources/_InternalTestSupport/SwiftTesting+Helpers.swift b/Sources/_InternalTestSupport/SwiftTesting+Helpers.swift index 69e8b06fee0..b53141810be 100644 --- a/Sources/_InternalTestSupport/SwiftTesting+Helpers.swift +++ b/Sources/_InternalTestSupport/SwiftTesting+Helpers.swift @@ -81,38 +81,58 @@ public func expectDirectoryDoesNotExist( ) } +/// Expects that the expression throws a CommandExecutionError and passes it to the provided throwing error handler. +/// - Parameters: +/// - expression: The expression expected to throw +/// - message: Optional message for the expectation +/// - sourceLocation: Source location for error reporting +/// - errorHandler: A throwing closure that receives the CommandExecutionError public func expectThrowsCommandExecutionError( _ expression: @autoclosure () async throws -> T, _ message: @autoclosure () -> Comment = "", sourceLocation: SourceLocation = #_sourceLocation, - _ errorHandler: (_ error: CommandExecutionError) -> Void = { _ in } -) async { - await expectAsyncThrowsError(try await expression(), message(), sourceLocation: sourceLocation) { error in - guard case SwiftPMError.executionFailure(let processError, let stdout, let stderr) = error, - case AsyncProcessResult.Error.nonZeroExit(let processResult) = processError, - processResult.exitStatus != .terminated(code: 0) - else { - Issue.record("Unexpected error type: \(error.interpolationDescription)", sourceLocation: sourceLocation) - return - } - errorHandler(CommandExecutionError(result: processResult, stdout: stdout, stderr: stderr)) + _ errorHandler: (_ error: CommandExecutionError) throws -> Void = { _ in } +) async rethrows { + if let commandError = await runCommandExpectingError(try await expression(), message(), sourceLocation: sourceLocation) { + try errorHandler(commandError) } } -/// An `async`-friendly replacement for `XCTAssertThrowsError`. -public func expectAsyncThrowsError( +/// Expects that the expression throws a CommandExecutionError and passes it to the provided non-throwing error handler. +/// This version can be called without `try` when the error handler doesn't throw. +/// - Parameters: +/// - expression: The expression expected to throw +/// - message: Optional message for the expectation +/// - sourceLocation: Source location for error reporting +/// - errorHandler: A non-throwing closure that receives the CommandExecutionError +public func expectThrowsCommandExecutionError( _ expression: @autoclosure () async throws -> T, - _ message: @autoclosure () -> Comment? = nil, + _ message: @autoclosure () -> Comment = "", sourceLocation: SourceLocation = #_sourceLocation, - _ errorHandler: (_ error: any Error) -> Void = { _ in } + _ errorHandler: (_ error: CommandExecutionError) -> Void ) async { - do { - _ = try await expression() - Issue.record( - message() ?? "Expected an error, which did not occur.", - sourceLocation: sourceLocation, - ) - } catch { - errorHandler(error) + if let commandError = await runCommandExpectingError(try await expression(), message(), sourceLocation: sourceLocation) { + errorHandler(commandError) + } +} + +/// Helper function that extracts a CommandExecutionError from an expression that's expected to throw +/// - Returns: The CommandExecutionError if the expected error was thrown, nil otherwise +private func runCommandExpectingError( + _ expression: @autoclosure () async throws -> T, + _ message: @autoclosure () -> Comment = "", + sourceLocation: SourceLocation +) async -> CommandExecutionError? { + let error = await #expect(throws: SwiftPMError.self, sourceLocation: sourceLocation) { + try await expression() } + + guard case .executionFailure(let processError, let stdout, let stderr) = error, + case AsyncProcessResult.Error.nonZeroExit(let processResult) = processError, + processResult.exitStatus != .terminated(code: 0) else { + Issue.record("Unexpected error type: \(error?.interpolationDescription)", sourceLocation: sourceLocation) + return nil + } + + return CommandExecutionError(result: processResult, stdout: stdout, stderr: stderr) } diff --git a/Tests/CommandsTests/APIDiffTests.swift b/Tests/CommandsTests/APIDiffTests.swift index 65a086235c9..570850f60d8 100644 --- a/Tests/CommandsTests/APIDiffTests.swift +++ b/Tests/CommandsTests/APIDiffTests.swift @@ -25,25 +25,6 @@ import _InternalTestSupport import Workspace import Testing -fileprivate func expectThrowsCommandExecutionError( - _ expression: @autoclosure () async throws -> T, - sourceLocation: SourceLocation = #_sourceLocation, - _ errorHandler: (_ error: CommandExecutionError) throws -> Void = { _ in } -) async rethrows { - let error = await #expect(throws: SwiftPMError.self, sourceLocation: sourceLocation) { - try await expression() - } - - guard case .executionFailure(let processError, let stdout, let stderr) = error, - case AsyncProcessResult.Error.nonZeroExit(let processResult) = processError, - processResult.exitStatus != .terminated(code: 0) else { - Issue.record("Unexpected error type: \(error?.interpolationDescription)", sourceLocation: sourceLocation) - return - } - try errorHandler(CommandExecutionError(result: processResult, stdout: stdout, stderr: stderr)) -} - - extension Trait where Self == Testing.ConditionTrait { public static var requiresAPIDigester: Self { enabled("This test requires a toolchain with swift-api-digester") { @@ -81,7 +62,7 @@ struct APIDiffTests { packageRoot.appending("Foo.swift"), string: "public let foo = 42" ) - try await expectThrowsCommandExecutionError(try await execute(["diagnose-api-breaking-changes", "1.2.3"], packagePath: packageRoot, buildSystem: buildSystem)) { error in + await expectThrowsCommandExecutionError(try await execute(["diagnose-api-breaking-changes", "1.2.3"], packagePath: packageRoot, buildSystem: buildSystem)) { error in #expect(!error.stdout.isEmpty) } } @@ -96,7 +77,7 @@ struct APIDiffTests { packageRoot.appending("Foo.swift"), string: "public let foo = 42" ) - try await expectThrowsCommandExecutionError(try await execute(["diagnose-api-breaking-changes", "1.2.3"], packagePath: packageRoot, buildSystem: buildSystem)) { error in + await expectThrowsCommandExecutionError(try await execute(["diagnose-api-breaking-changes", "1.2.3"], packagePath: packageRoot, buildSystem: buildSystem)) { error in #expect(error.stdout.contains("1 breaking change detected in Foo")) #expect(error.stdout.contains("💔 API breakage: func foo() has been removed")) } @@ -119,7 +100,7 @@ struct APIDiffTests { packageRoot.appending(components: "Sources", "Qux", "Qux.swift"), string: "public class Qux { private let x = 1 }" ) - try await expectThrowsCommandExecutionError(try await execute(["diagnose-api-breaking-changes", "1.2.3"], packagePath: packageRoot, buildSystem: buildSystem)) { error in + await expectThrowsCommandExecutionError(try await execute(["diagnose-api-breaking-changes", "1.2.3"], packagePath: packageRoot, buildSystem: buildSystem)) { error in withKnownIssue { #expect(error.stdout.contains("2 breaking changes detected in Qux")) #expect(error.stdout.contains("💔 API breakage: class Qux has generic signature change from to ")) @@ -154,7 +135,7 @@ struct APIDiffTests { customAllowlistPath, string: "API breakage: class Qux has generic signature change from to \n" ) - try await expectThrowsCommandExecutionError( + await expectThrowsCommandExecutionError( try await execute(["diagnose-api-breaking-changes", "1.2.3", "--breakage-allowlist-path", customAllowlistPath.pathString], packagePath: packageRoot, buildSystem: buildSystem) ) { error in @@ -277,7 +258,7 @@ struct APIDiffTests { } // Test diagnostics - try await expectThrowsCommandExecutionError( + await expectThrowsCommandExecutionError( try await execute(["diagnose-api-breaking-changes", "1.2.3", "--targets", "NotATarget", "Exec", "--products", "NotAProduct", "Exec"], packagePath: packageRoot, buildSystem: buildSystem) ) { error in @@ -305,13 +286,13 @@ struct APIDiffTests { } """ ) - try await expectThrowsCommandExecutionError(try await execute(["diagnose-api-breaking-changes", "1.2.3"], packagePath: packageRoot, buildSystem: buildSystem)) { error in + await expectThrowsCommandExecutionError(try await execute(["diagnose-api-breaking-changes", "1.2.3"], packagePath: packageRoot, buildSystem: buildSystem)) { error in #expect(error.stdout.contains("1 breaking change detected in Bar")) #expect(error.stdout.contains("💔 API breakage: func bar() has return type change from Swift.Int to Swift.String")) } // Report an error if we explicitly ask to diff a C-family target - try await expectThrowsCommandExecutionError(try await execute(["diagnose-api-breaking-changes", "1.2.3", "--targets", "Foo"], packagePath: packageRoot, buildSystem: buildSystem)) { error in + await expectThrowsCommandExecutionError(try await execute(["diagnose-api-breaking-changes", "1.2.3", "--targets", "Foo"], packagePath: packageRoot, buildSystem: buildSystem)) { error in #expect(error.stderr.contains("error: 'Foo' is not a Swift language target")) } } @@ -413,7 +394,7 @@ struct APIDiffTests { func testBadTreeish(buildSystem: BuildSystemProvider.Kind) async throws { try await fixture(name: "Miscellaneous/APIDiff/") { fixturePath in let packageRoot = fixturePath.appending("Foo") - try await expectThrowsCommandExecutionError(try await execute(["diagnose-api-breaking-changes", "7.8.9"], packagePath: packageRoot, buildSystem: buildSystem)) { error in + await expectThrowsCommandExecutionError(try await execute(["diagnose-api-breaking-changes", "7.8.9"], packagePath: packageRoot, buildSystem: buildSystem)) { error in #expect(error.stderr.contains("error: Couldn’t get revision")) } } @@ -433,7 +414,7 @@ struct APIDiffTests { ) try repo.stage(file: "Foo.swift") try repo.commit(message: "Add foo") - try await expectThrowsCommandExecutionError( + await expectThrowsCommandExecutionError( try await execute(["diagnose-api-breaking-changes", "main", "--baseline-dir", baselineDir.pathString], packagePath: packageRoot, buildSystem: buildSystem) @@ -473,7 +454,7 @@ struct APIDiffTests { let repo = GitRepository(path: packageRoot) let revision = try repo.resolveRevision(identifier: "1.2.3") - try await expectThrowsCommandExecutionError( + await expectThrowsCommandExecutionError( try await execute(["diagnose-api-breaking-changes", "1.2.3", "--baseline-dir", baselineDir.pathString], packagePath: packageRoot, buildSystem: buildSystem) ) { error in #expect(error.stdout.contains("1 breaking change detected in Foo")) @@ -541,7 +522,7 @@ struct APIDiffTests { // Accomodate filesystems with low resolution timestamps try await Task.sleep(for: .seconds(1)) - try await expectThrowsCommandExecutionError( + await expectThrowsCommandExecutionError( try await execute(["diagnose-api-breaking-changes", "1.2.3", "--baseline-dir", baselineDir.pathString, "--regenerate-baseline"], packagePath: packageRoot, @@ -556,7 +537,7 @@ struct APIDiffTests { @Test(arguments: SupportedBuildSystemOnAllPlatforms) func testOldName(buildSystem: BuildSystemProvider.Kind) async throws { - try await expectThrowsCommandExecutionError(try await execute(["experimental-api-diff", "1.2.3", "--regenerate-baseline"], packagePath: nil, buildSystem: buildSystem)) { error in + await expectThrowsCommandExecutionError(try await execute(["experimental-api-diff", "1.2.3", "--regenerate-baseline"], packagePath: nil, buildSystem: buildSystem)) { error in #expect(error.stdout.contains("`swift package experimental-api-diff` has been renamed to `swift package diagnose-api-breaking-changes`")) } } @@ -565,7 +546,7 @@ struct APIDiffTests { func testBrokenAPIDiff(buildSystem: BuildSystemProvider.Kind) async throws { try await fixture(name: "Miscellaneous/APIDiff/") { fixturePath in let packageRoot = fixturePath.appending("BrokenPkg") - try await expectThrowsCommandExecutionError(try await execute(["diagnose-api-breaking-changes", "1.2.3"], packagePath: packageRoot, buildSystem: buildSystem)) { error in + await expectThrowsCommandExecutionError(try await execute(["diagnose-api-breaking-changes", "1.2.3"], packagePath: packageRoot, buildSystem: buildSystem)) { error in let expectedError: String if buildSystem == .swiftbuild { expectedError = "error: Build failed" From 22aecc8da66c8e2a83647bef2befde8c59ce2b34 Mon Sep 17 00:00:00 2001 From: Paul LeMarquand Date: Thu, 11 Sep 2025 09:52:07 -0400 Subject: [PATCH 2/7] Explicitly type error value --- Sources/_InternalTestSupport/SwiftTesting+Helpers.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/_InternalTestSupport/SwiftTesting+Helpers.swift b/Sources/_InternalTestSupport/SwiftTesting+Helpers.swift index b53141810be..081e261a24d 100644 --- a/Sources/_InternalTestSupport/SwiftTesting+Helpers.swift +++ b/Sources/_InternalTestSupport/SwiftTesting+Helpers.swift @@ -123,7 +123,7 @@ private func runCommandExpectingError( _ message: @autoclosure () -> Comment = "", sourceLocation: SourceLocation ) async -> CommandExecutionError? { - let error = await #expect(throws: SwiftPMError.self, sourceLocation: sourceLocation) { + let error: SwiftPMError? = await #expect(throws: SwiftPMError.self, sourceLocation: sourceLocation) { try await expression() } From f80cfad433c9d1db7b03835c1ab69ba4a3914303 Mon Sep 17 00:00:00 2001 From: Paul LeMarquand Date: Fri, 12 Sep 2025 16:41:49 -0400 Subject: [PATCH 3/7] Cleanup --- .../SwiftTesting+Helpers.swift | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/Sources/_InternalTestSupport/SwiftTesting+Helpers.swift b/Sources/_InternalTestSupport/SwiftTesting+Helpers.swift index 081e261a24d..2db5040beea 100644 --- a/Sources/_InternalTestSupport/SwiftTesting+Helpers.swift +++ b/Sources/_InternalTestSupport/SwiftTesting+Helpers.swift @@ -93,9 +93,12 @@ public func expectThrowsCommandExecutionError( sourceLocation: SourceLocation = #_sourceLocation, _ errorHandler: (_ error: CommandExecutionError) throws -> Void = { _ in } ) async rethrows { - if let commandError = await runCommandExpectingError(try await expression(), message(), sourceLocation: sourceLocation) { - try errorHandler(commandError) - } + _ = try await _expectThrowsCommandExecutionError( + { try await expression() }, + { message() }, + sourceLocation: sourceLocation, + errorHandler + ) } /// Expects that the expression throws a CommandExecutionError and passes it to the provided non-throwing error handler. @@ -111,28 +114,31 @@ public func expectThrowsCommandExecutionError( sourceLocation: SourceLocation = #_sourceLocation, _ errorHandler: (_ error: CommandExecutionError) -> Void ) async { - if let commandError = await runCommandExpectingError(try await expression(), message(), sourceLocation: sourceLocation) { - errorHandler(commandError) + _ = try? await _expectThrowsCommandExecutionError( + { try await expression() }, + { message() }, + sourceLocation: sourceLocation + ) { error in + errorHandler(error) + return () } } -/// Helper function that extracts a CommandExecutionError from an expression that's expected to throw -/// - Returns: The CommandExecutionError if the expected error was thrown, nil otherwise -private func runCommandExpectingError( - _ expression: @autoclosure () async throws -> T, - _ message: @autoclosure () -> Comment = "", - sourceLocation: SourceLocation -) async -> CommandExecutionError? { - let error: SwiftPMError? = await #expect(throws: SwiftPMError.self, sourceLocation: sourceLocation) { - try await expression() +private func _expectThrowsCommandExecutionError( + _ expressionClosure: () async throws -> Any, + _ message: () -> Comment, + sourceLocation: SourceLocation, + _ errorHandler: (_ error: CommandExecutionError) throws -> R +) async rethrows -> R? { + let error = await #expect(throws: SwiftPMError.self, message(), sourceLocation: sourceLocation) { + try await expressionClosure() } guard case .executionFailure(let processError, let stdout, let stderr) = error, case AsyncProcessResult.Error.nonZeroExit(let processResult) = processError, processResult.exitStatus != .terminated(code: 0) else { - Issue.record("Unexpected error type: \(error?.interpolationDescription)", sourceLocation: sourceLocation) + Issue.record("Unexpected error type: \(error?.interpolationDescription ?? "")", sourceLocation: sourceLocation) return nil } - - return CommandExecutionError(result: processResult, stdout: stdout, stderr: stderr) + return try errorHandler(CommandExecutionError(result: processResult, stdout: stdout, stderr: stderr)) } From 32a6c16dcc28a2421602eb2b85d4bb519f786898 Mon Sep 17 00:00:00 2001 From: Paul LeMarquand Date: Sat, 13 Sep 2025 19:09:55 -0400 Subject: [PATCH 4/7] Add guard --- Sources/_InternalTestSupport/SwiftTesting+Helpers.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/_InternalTestSupport/SwiftTesting+Helpers.swift b/Sources/_InternalTestSupport/SwiftTesting+Helpers.swift index 2db5040beea..38afbbcdec7 100644 --- a/Sources/_InternalTestSupport/SwiftTesting+Helpers.swift +++ b/Sources/_InternalTestSupport/SwiftTesting+Helpers.swift @@ -134,7 +134,8 @@ private func _expectThrowsCommandExecutionError( try await expressionClosure() } - guard case .executionFailure(let processError, let stdout, let stderr) = error, + guard let error = error, + case .executionFailure(let processError, let stdout, let stderr) = error, case AsyncProcessResult.Error.nonZeroExit(let processResult) = processError, processResult.exitStatus != .terminated(code: 0) else { Issue.record("Unexpected error type: \(error?.interpolationDescription ?? "")", sourceLocation: sourceLocation) From e7c1a684d1dbd2b6f652d044e48ae2910494287d Mon Sep 17 00:00:00 2001 From: Paul LeMarquand Date: Sun, 14 Sep 2025 12:39:20 -0400 Subject: [PATCH 5/7] Compiler, why have I confused you? --- .../_InternalTestSupport/SwiftTesting+Helpers.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/_InternalTestSupport/SwiftTesting+Helpers.swift b/Sources/_InternalTestSupport/SwiftTesting+Helpers.swift index 38afbbcdec7..73f17333ff9 100644 --- a/Sources/_InternalTestSupport/SwiftTesting+Helpers.swift +++ b/Sources/_InternalTestSupport/SwiftTesting+Helpers.swift @@ -124,21 +124,21 @@ public func expectThrowsCommandExecutionError( } } -private func _expectThrowsCommandExecutionError( - _ expressionClosure: () async throws -> Any, +private func _expectThrowsCommandExecutionError( + _ expressionClosure: () async throws -> T, _ message: () -> Comment, sourceLocation: SourceLocation, _ errorHandler: (_ error: CommandExecutionError) throws -> R ) async rethrows -> R? { - let error = await #expect(throws: SwiftPMError.self, message(), sourceLocation: sourceLocation) { + let err = await #expect(throws: SwiftPMError.self, message(), sourceLocation: sourceLocation) { try await expressionClosure() } - guard let error = error, + guard let error = err, case .executionFailure(let processError, let stdout, let stderr) = error, case AsyncProcessResult.Error.nonZeroExit(let processResult) = processError, processResult.exitStatus != .terminated(code: 0) else { - Issue.record("Unexpected error type: \(error?.interpolationDescription ?? "")", sourceLocation: sourceLocation) + Issue.record("Unexpected error type: \(err?.interpolationDescription ?? "")", sourceLocation: sourceLocation) return nil } return try errorHandler(CommandExecutionError(result: processResult, stdout: stdout, stderr: stderr)) From a51e90a000ab731f2689bf192c5c6dbf18ec9943 Mon Sep 17 00:00:00 2001 From: Paul LeMarquand Date: Mon, 15 Sep 2025 12:25:18 -0400 Subject: [PATCH 6/7] Support 6.1 as well --- .../SwiftTesting+Helpers.swift | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/Sources/_InternalTestSupport/SwiftTesting+Helpers.swift b/Sources/_InternalTestSupport/SwiftTesting+Helpers.swift index 73f17333ff9..0ccbfb1ac35 100644 --- a/Sources/_InternalTestSupport/SwiftTesting+Helpers.swift +++ b/Sources/_InternalTestSupport/SwiftTesting+Helpers.swift @@ -93,12 +93,7 @@ public func expectThrowsCommandExecutionError( sourceLocation: SourceLocation = #_sourceLocation, _ errorHandler: (_ error: CommandExecutionError) throws -> Void = { _ in } ) async rethrows { - _ = try await _expectThrowsCommandExecutionError( - { try await expression() }, - { message() }, - sourceLocation: sourceLocation, - errorHandler - ) + _ = try await _expectThrowsCommandExecutionError(try await expression(), message(), sourceLocation, errorHandler) } /// Expects that the expression throws a CommandExecutionError and passes it to the provided non-throwing error handler. @@ -114,32 +109,42 @@ public func expectThrowsCommandExecutionError( sourceLocation: SourceLocation = #_sourceLocation, _ errorHandler: (_ error: CommandExecutionError) -> Void ) async { - _ = try? await _expectThrowsCommandExecutionError( - { try await expression() }, - { message() }, - sourceLocation: sourceLocation - ) { error in + _ = try? await _expectThrowsCommandExecutionError(try await expression(), message(), sourceLocation) { error in errorHandler(error) return () } } private func _expectThrowsCommandExecutionError( - _ expressionClosure: () async throws -> T, - _ message: () -> Comment, - sourceLocation: SourceLocation, + _ expressionClosure: @autoclosure () async throws -> T, + _ message: @autoclosure () -> Comment, + _ sourceLocation: SourceLocation, _ errorHandler: (_ error: CommandExecutionError) throws -> R ) async rethrows -> R? { + #if compiler(>=6.1) let err = await #expect(throws: SwiftPMError.self, message(), sourceLocation: sourceLocation) { try await expressionClosure() } + #else + // Older toolchains don't have https://github.com/swiftlang/swift-evolution/blob/main/proposals/testing/0006-return-errors-from-expect-throws.md + // This can be removed once the CI smoke jobs build with 6.2. + var err: SwiftPMError? + await #expect(throws: SwiftPMError.self, message(), sourceLocation: sourceLocation) { + do { + let _ = try await expressionClosure() + } catch { + err = error as? SwiftPMError + throw error + } + } + #endif guard let error = err, case .executionFailure(let processError, let stdout, let stderr) = error, case AsyncProcessResult.Error.nonZeroExit(let processResult) = processError, processResult.exitStatus != .terminated(code: 0) else { Issue.record("Unexpected error type: \(err?.interpolationDescription ?? "")", sourceLocation: sourceLocation) - return nil + return Optional.none } return try errorHandler(CommandExecutionError(result: processResult, stdout: stdout, stderr: stderr)) } From a8a051235209e14f3d3b7d80ce1a99c7a3e663a5 Mon Sep 17 00:00:00 2001 From: Paul LeMarquand Date: Mon, 15 Sep 2025 14:50:46 -0400 Subject: [PATCH 7/7] Just use the old way --- Sources/_InternalTestSupport/SwiftTesting+Helpers.swift | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Sources/_InternalTestSupport/SwiftTesting+Helpers.swift b/Sources/_InternalTestSupport/SwiftTesting+Helpers.swift index 0ccbfb1ac35..964fda5e5ee 100644 --- a/Sources/_InternalTestSupport/SwiftTesting+Helpers.swift +++ b/Sources/_InternalTestSupport/SwiftTesting+Helpers.swift @@ -121,11 +121,6 @@ private func _expectThrowsCommandExecutionError( _ sourceLocation: SourceLocation, _ errorHandler: (_ error: CommandExecutionError) throws -> R ) async rethrows -> R? { - #if compiler(>=6.1) - let err = await #expect(throws: SwiftPMError.self, message(), sourceLocation: sourceLocation) { - try await expressionClosure() - } - #else // Older toolchains don't have https://github.com/swiftlang/swift-evolution/blob/main/proposals/testing/0006-return-errors-from-expect-throws.md // This can be removed once the CI smoke jobs build with 6.2. var err: SwiftPMError? @@ -137,7 +132,6 @@ private func _expectThrowsCommandExecutionError( throw error } } - #endif guard let error = err, case .executionFailure(let processError, let stdout, let stderr) = error,