@@ -25,25 +25,6 @@ import _InternalTestSupport
25
25
import Workspace
26
26
import Testing
27
27
28
- fileprivate func expectThrowsCommandExecutionError< T> (
29
- _ expression: @autoclosure ( ) async throws -> T ,
30
- sourceLocation: SourceLocation = #_sourceLocation,
31
- _ errorHandler: ( _ error: CommandExecutionError ) throws -> Void = { _ in }
32
- ) async rethrows {
33
- let error = await #expect( throws: SwiftPMError . self, sourceLocation: sourceLocation) {
34
- try await expression ( )
35
- }
36
-
37
- guard case . executionFailure( let processError, let stdout, let stderr) = error,
38
- case AsyncProcessResult . Error . nonZeroExit( let processResult) = processError,
39
- processResult. exitStatus != . terminated( code: 0 ) else {
40
- Issue . record ( " Unexpected error type: \( error? . interpolationDescription) " , sourceLocation: sourceLocation)
41
- return
42
- }
43
- try errorHandler ( CommandExecutionError ( result: processResult, stdout: stdout, stderr: stderr) )
44
- }
45
-
46
-
47
28
extension Trait where Self == Testing . ConditionTrait {
48
29
public static var requiresAPIDigester : Self {
49
30
enabled ( " This test requires a toolchain with swift-api-digester " ) {
@@ -81,7 +62,7 @@ struct APIDiffTests {
81
62
packageRoot. appending ( " Foo.swift " ) ,
82
63
string: " public let foo = 42 "
83
64
)
84
- try await expectThrowsCommandExecutionError ( try await execute ( [ " diagnose-api-breaking-changes " , " 1.2.3 " ] , packagePath: packageRoot, buildSystem: buildSystem) ) { error in
65
+ await expectThrowsCommandExecutionError ( try await execute ( [ " diagnose-api-breaking-changes " , " 1.2.3 " ] , packagePath: packageRoot, buildSystem: buildSystem) ) { error in
85
66
#expect( !error. stdout. isEmpty)
86
67
}
87
68
}
@@ -96,7 +77,7 @@ struct APIDiffTests {
96
77
packageRoot. appending ( " Foo.swift " ) ,
97
78
string: " public let foo = 42 "
98
79
)
99
- try await expectThrowsCommandExecutionError ( try await execute ( [ " diagnose-api-breaking-changes " , " 1.2.3 " ] , packagePath: packageRoot, buildSystem: buildSystem) ) { error in
80
+ await expectThrowsCommandExecutionError ( try await execute ( [ " diagnose-api-breaking-changes " , " 1.2.3 " ] , packagePath: packageRoot, buildSystem: buildSystem) ) { error in
100
81
#expect( error. stdout. contains ( " 1 breaking change detected in Foo " ) )
101
82
#expect( error. stdout. contains ( " 💔 API breakage: func foo() has been removed " ) )
102
83
}
@@ -119,7 +100,7 @@ struct APIDiffTests {
119
100
packageRoot. appending ( components: " Sources " , " Qux " , " Qux.swift " ) ,
120
101
string: " public class Qux<T, U> { private let x = 1 } "
121
102
)
122
- try await expectThrowsCommandExecutionError ( try await execute ( [ " diagnose-api-breaking-changes " , " 1.2.3 " ] , packagePath: packageRoot, buildSystem: buildSystem) ) { error in
103
+ await expectThrowsCommandExecutionError ( try await execute ( [ " diagnose-api-breaking-changes " , " 1.2.3 " ] , packagePath: packageRoot, buildSystem: buildSystem) ) { error in
123
104
withKnownIssue {
124
105
#expect( error. stdout. contains ( " 2 breaking changes detected in Qux " ) )
125
106
#expect( error. stdout. contains ( " 💔 API breakage: class Qux has generic signature change from <T> to <T, U> " ) )
@@ -154,7 +135,7 @@ struct APIDiffTests {
154
135
customAllowlistPath,
155
136
string: " API breakage: class Qux has generic signature change from <T> to <T, U> \n "
156
137
)
157
- try await expectThrowsCommandExecutionError (
138
+ await expectThrowsCommandExecutionError (
158
139
try await execute ( [ " diagnose-api-breaking-changes " , " 1.2.3 " , " --breakage-allowlist-path " , customAllowlistPath. pathString] ,
159
140
packagePath: packageRoot, buildSystem: buildSystem)
160
141
) { error in
@@ -277,7 +258,7 @@ struct APIDiffTests {
277
258
}
278
259
279
260
// Test diagnostics
280
- try await expectThrowsCommandExecutionError (
261
+ await expectThrowsCommandExecutionError (
281
262
try await execute ( [ " diagnose-api-breaking-changes " , " 1.2.3 " , " --targets " , " NotATarget " , " Exec " , " --products " , " NotAProduct " , " Exec " ] ,
282
263
packagePath: packageRoot, buildSystem: buildSystem)
283
264
) { error in
@@ -305,13 +286,13 @@ struct APIDiffTests {
305
286
}
306
287
"""
307
288
)
308
- try await expectThrowsCommandExecutionError ( try await execute ( [ " diagnose-api-breaking-changes " , " 1.2.3 " ] , packagePath: packageRoot, buildSystem: buildSystem) ) { error in
289
+ await expectThrowsCommandExecutionError ( try await execute ( [ " diagnose-api-breaking-changes " , " 1.2.3 " ] , packagePath: packageRoot, buildSystem: buildSystem) ) { error in
309
290
#expect( error. stdout. contains ( " 1 breaking change detected in Bar " ) )
310
291
#expect( error. stdout. contains ( " 💔 API breakage: func bar() has return type change from Swift.Int to Swift.String " ) )
311
292
}
312
293
313
294
// Report an error if we explicitly ask to diff a C-family target
314
- try await expectThrowsCommandExecutionError ( try await execute ( [ " diagnose-api-breaking-changes " , " 1.2.3 " , " --targets " , " Foo " ] , packagePath: packageRoot, buildSystem: buildSystem) ) { error in
295
+ await expectThrowsCommandExecutionError ( try await execute ( [ " diagnose-api-breaking-changes " , " 1.2.3 " , " --targets " , " Foo " ] , packagePath: packageRoot, buildSystem: buildSystem) ) { error in
315
296
#expect( error. stderr. contains ( " error: 'Foo' is not a Swift language target " ) )
316
297
}
317
298
}
@@ -413,7 +394,7 @@ struct APIDiffTests {
413
394
func testBadTreeish( buildSystem: BuildSystemProvider . Kind ) async throws {
414
395
try await fixture ( name: " Miscellaneous/APIDiff/ " ) { fixturePath in
415
396
let packageRoot = fixturePath. appending ( " Foo " )
416
- try await expectThrowsCommandExecutionError ( try await execute ( [ " diagnose-api-breaking-changes " , " 7.8.9 " ] , packagePath: packageRoot, buildSystem: buildSystem) ) { error in
397
+ await expectThrowsCommandExecutionError ( try await execute ( [ " diagnose-api-breaking-changes " , " 7.8.9 " ] , packagePath: packageRoot, buildSystem: buildSystem) ) { error in
417
398
#expect( error. stderr. contains ( " error: Couldn’t get revision " ) )
418
399
}
419
400
}
@@ -433,7 +414,7 @@ struct APIDiffTests {
433
414
)
434
415
try repo. stage ( file: " Foo.swift " )
435
416
try repo. commit ( message: " Add foo " )
436
- try await expectThrowsCommandExecutionError (
417
+ await expectThrowsCommandExecutionError (
437
418
try await execute ( [ " diagnose-api-breaking-changes " , " main " , " --baseline-dir " , baselineDir. pathString] ,
438
419
packagePath: packageRoot,
439
420
buildSystem: buildSystem)
@@ -473,7 +454,7 @@ struct APIDiffTests {
473
454
let repo = GitRepository ( path: packageRoot)
474
455
let revision = try repo. resolveRevision ( identifier: " 1.2.3 " )
475
456
476
- try await expectThrowsCommandExecutionError (
457
+ await expectThrowsCommandExecutionError (
477
458
try await execute ( [ " diagnose-api-breaking-changes " , " 1.2.3 " , " --baseline-dir " , baselineDir. pathString] , packagePath: packageRoot, buildSystem: buildSystem)
478
459
) { error in
479
460
#expect( error. stdout. contains ( " 1 breaking change detected in Foo " ) )
@@ -541,7 +522,7 @@ struct APIDiffTests {
541
522
// Accomodate filesystems with low resolution timestamps
542
523
try await Task . sleep ( for: . seconds( 1 ) )
543
524
544
- try await expectThrowsCommandExecutionError (
525
+ await expectThrowsCommandExecutionError (
545
526
try await execute ( [ " diagnose-api-breaking-changes " , " 1.2.3 " ,
546
527
" --baseline-dir " , baselineDir. pathString, " --regenerate-baseline " ] ,
547
528
packagePath: packageRoot,
@@ -556,7 +537,7 @@ struct APIDiffTests {
556
537
557
538
@Test ( arguments: SupportedBuildSystemOnAllPlatforms)
558
539
func testOldName( buildSystem: BuildSystemProvider . Kind ) async throws {
559
- try await expectThrowsCommandExecutionError ( try await execute ( [ " experimental-api-diff " , " 1.2.3 " , " --regenerate-baseline " ] , packagePath: nil , buildSystem: buildSystem) ) { error in
540
+ await expectThrowsCommandExecutionError ( try await execute ( [ " experimental-api-diff " , " 1.2.3 " , " --regenerate-baseline " ] , packagePath: nil , buildSystem: buildSystem) ) { error in
560
541
#expect( error. stdout. contains ( " `swift package experimental-api-diff` has been renamed to `swift package diagnose-api-breaking-changes` " ) )
561
542
}
562
543
}
@@ -565,7 +546,7 @@ struct APIDiffTests {
565
546
func testBrokenAPIDiff( buildSystem: BuildSystemProvider . Kind ) async throws {
566
547
try await fixture ( name: " Miscellaneous/APIDiff/ " ) { fixturePath in
567
548
let packageRoot = fixturePath. appending ( " BrokenPkg " )
568
- try await expectThrowsCommandExecutionError ( try await execute ( [ " diagnose-api-breaking-changes " , " 1.2.3 " ] , packagePath: packageRoot, buildSystem: buildSystem) ) { error in
549
+ await expectThrowsCommandExecutionError ( try await execute ( [ " diagnose-api-breaking-changes " , " 1.2.3 " ] , packagePath: packageRoot, buildSystem: buildSystem) ) { error in
569
550
let expectedError : String
570
551
if buildSystem == . swiftbuild {
571
552
expectedError = " error: Build failed "
0 commit comments