@@ -27,11 +27,20 @@ final class APIDiffTests: XCTestCase {
27
27
return try SwiftPMProduct . SwiftPackage. execute ( args, packagePath: packagePath, env: environment)
28
28
}
29
29
30
+ func skipIfApiDigesterUnsupported( ) throws {
31
+ guard let tool = try ? Resources . default. toolchain. getSwiftAPIDigester ( ) else {
32
+ throw XCTSkip ( " swift-api-digester unavailable " )
33
+ }
34
+ guard localFileSystem. isSymlink ( tool) else {
35
+ // The version of Swift with a supported swift-api-digester doesn't have
36
+ // a version number yet, so use whether or not the tool is a symlink to
37
+ // determine if it's from a recent snapshot.
38
+ throw XCTSkip ( " swift-api-digester is too old " )
39
+ }
40
+ }
41
+
30
42
func testSimpleAPIDiff( ) throws {
31
- #if os(macOS)
32
- guard ( try ? Resources . default. toolchain. getSwiftAPIDigester ( ) ) != nil else {
33
- throw XCTSkip ( " swift-api-digester not available " )
34
- }
43
+ try skipIfApiDigesterUnsupported ( )
35
44
fixture ( name: " Miscellaneous/APIDiff/ " ) { prefix in
36
45
let packageRoot = prefix. appending ( component: " Foo " )
37
46
// Overwrite the existing decl.
@@ -47,16 +56,10 @@ final class APIDiffTests: XCTestCase {
47
56
XCTAssertTrue ( output. contains ( " 💔 API breakage: func foo() has been removed " ) )
48
57
}
49
58
}
50
- #else
51
- throw XCTSkip ( " Test unsupported on current platform " )
52
- #endif
53
59
}
54
60
55
61
func testMultiTargetAPIDiff( ) throws {
56
- #if os(macOS)
57
- guard ( try ? Resources . default. toolchain. getSwiftAPIDigester ( ) ) != nil else {
58
- throw XCTSkip ( " swift-api-digester not available " )
59
- }
62
+ try skipIfApiDigesterUnsupported ( )
60
63
fixture ( name: " Miscellaneous/APIDiff/ " ) { prefix in
61
64
let packageRoot = prefix. appending ( component: " Bar " )
62
65
try localFileSystem. writeFileContents ( packageRoot. appending ( components: " Sources " , " Baz " , " Baz.swift " ) ) {
@@ -77,9 +80,6 @@ final class APIDiffTests: XCTestCase {
77
80
XCTAssertTrue ( output. contains ( " 💔 API breakage: func bar() has been removed " ) )
78
81
}
79
82
}
80
- #else
81
- throw XCTSkip ( " Test unsupported on current platform " )
82
- #endif
83
83
}
84
84
85
85
func testBreakageAllowlist( ) throws {
@@ -120,10 +120,7 @@ final class APIDiffTests: XCTestCase {
120
120
}
121
121
122
122
func testCheckVendedModulesOnly( ) throws {
123
- #if os(macOS)
124
- guard ( try ? Resources . default. toolchain. getSwiftAPIDigester ( ) ) != nil else {
125
- throw XCTSkip ( " swift-api-digester not available " )
126
- }
123
+ try skipIfApiDigesterUnsupported ( )
127
124
fixture ( name: " Miscellaneous/APIDiff/ " ) { prefix in
128
125
let packageRoot = prefix. appending ( component: " NonAPILibraryTargets " )
129
126
try localFileSystem. writeFileContents ( packageRoot. appending ( components: " Sources " , " Foo " , " Foo.swift " ) ) {
@@ -156,16 +153,10 @@ final class APIDiffTests: XCTestCase {
156
153
XCTAssertFalse ( output. contains ( " 💔 API breakage: var Qux.x has been removed " ) )
157
154
}
158
155
}
159
- #else
160
- throw XCTSkip ( " Test unsupported on current platform " )
161
- #endif
162
156
}
163
157
164
158
func testFilters( ) throws {
165
- #if os(macOS)
166
- guard ( try ? Resources . default. toolchain. getSwiftAPIDigester ( ) ) != nil else {
167
- throw XCTSkip ( " swift-api-digester not available " )
168
- }
159
+ try skipIfApiDigesterUnsupported ( )
169
160
fixture ( name: " Miscellaneous/APIDiff/ " ) { prefix in
170
161
let packageRoot = prefix. appending ( component: " NonAPILibraryTargets " )
171
162
try localFileSystem. writeFileContents ( packageRoot. appending ( components: " Sources " , " Foo " , " Foo.swift " ) ) {
@@ -234,16 +225,10 @@ final class APIDiffTests: XCTestCase {
234
225
XCTAssertTrue ( stderr. contains ( " 'Exec' is not a library target " ) )
235
226
}
236
227
}
237
- #else
238
- throw XCTSkip ( " Test unsupported on current platform " )
239
- #endif
240
228
}
241
229
242
230
func testAPIDiffOfModuleWithCDependency( ) throws {
243
- #if os(macOS)
244
- guard ( try ? Resources . default. toolchain. getSwiftAPIDigester ( ) ) != nil else {
245
- throw XCTSkip ( " swift-api-digester not available " )
246
- }
231
+ try skipIfApiDigesterUnsupported ( )
247
232
fixture ( name: " Miscellaneous/APIDiff/ " ) { prefix in
248
233
let packageRoot = prefix. appending ( component: " CTargetDep " )
249
234
// Overwrite the existing decl.
@@ -276,16 +261,10 @@ final class APIDiffTests: XCTestCase {
276
261
XCTAssertTrue ( stderr. contains ( " error: 'Foo' is not a Swift language target " ) )
277
262
}
278
263
}
279
- #else
280
- throw XCTSkip ( " Test unsupported on current platform " )
281
- #endif
282
264
}
283
265
284
266
func testNoBreakingChanges( ) throws {
285
- #if os(macOS)
286
- guard ( try ? Resources . default. toolchain. getSwiftAPIDigester ( ) ) != nil else {
287
- throw XCTSkip ( " swift-api-digester not available " )
288
- }
267
+ try skipIfApiDigesterUnsupported ( )
289
268
fixture ( name: " Miscellaneous/APIDiff/ " ) { prefix in
290
269
let packageRoot = prefix. appending ( component: " Bar " )
291
270
// Introduce an API-compatible change
@@ -296,16 +275,10 @@ final class APIDiffTests: XCTestCase {
296
275
XCTAssertTrue ( output. contains ( " No breaking changes detected in Baz " ) )
297
276
XCTAssertTrue ( output. contains ( " No breaking changes detected in Qux " ) )
298
277
}
299
- #else
300
- throw XCTSkip ( " Test unsupported on current platform " )
301
- #endif
302
278
}
303
279
304
280
func testAPIDiffAfterAddingNewTarget( ) throws {
305
- #if os(macOS)
306
- guard ( try ? Resources . default. toolchain. getSwiftAPIDigester ( ) ) != nil else {
307
- throw XCTSkip ( " swift-api-digester not available " )
308
- }
281
+ try skipIfApiDigesterUnsupported ( )
309
282
fixture ( name: " Miscellaneous/APIDiff/ " ) { prefix in
310
283
let packageRoot = prefix. appending ( component: " Bar " )
311
284
try localFileSystem. createDirectory ( packageRoot. appending ( components: " Sources " , " Foo " ) )
@@ -336,16 +309,10 @@ final class APIDiffTests: XCTestCase {
336
309
XCTAssertTrue ( output. contains ( " No breaking changes detected in Qux " ) )
337
310
XCTAssertTrue ( output. contains ( " Skipping Foo because it does not exist in the baseline " ) )
338
311
}
339
- #else
340
- throw XCTSkip ( " Test unsupported on current platform " )
341
- #endif
342
312
}
343
313
344
314
func testBadTreeish( ) throws {
345
- #if os(macOS)
346
- guard ( try ? Resources . default. toolchain. getSwiftAPIDigester ( ) ) != nil else {
347
- throw XCTSkip ( " swift-api-digester not available " )
348
- }
315
+ try skipIfApiDigesterUnsupported ( )
349
316
fixture ( name: " Miscellaneous/APIDiff/ " ) { prefix in
350
317
let packageRoot = prefix. appending ( component: " Foo " )
351
318
XCTAssertThrowsError ( try execute ( [ " experimental-api-diff " , " 7.8.9 " ] , packagePath: packageRoot) ) { error in
@@ -356,9 +323,6 @@ final class APIDiffTests: XCTestCase {
356
323
XCTAssertTrue ( stderr. contains ( " error: Couldn’t check out revision ‘7.8.9’ " ) )
357
324
}
358
325
}
359
- #else
360
- throw XCTSkip ( " Test unsupported on current platform " )
361
- #endif
362
326
}
363
327
364
328
func testBaselineDirOverride( ) throws {
0 commit comments