@@ -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,16 +80,10 @@ 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 testCheckVendedModulesOnly( ) throws {
86
- #if os(macOS)
87
- guard ( try ? Resources . default. toolchain. getSwiftAPIDigester ( ) ) != nil else {
88
- throw XCTSkip ( " swift-api-digester not available " )
89
- }
86
+ try skipIfApiDigesterUnsupported ( )
90
87
fixture ( name: " Miscellaneous/APIDiff/ " ) { prefix in
91
88
let packageRoot = prefix. appending ( component: " NonAPILibraryTargets " )
92
89
try localFileSystem. writeFileContents ( packageRoot. appending ( components: " Sources " , " Foo " , " Foo.swift " ) ) {
@@ -119,16 +116,10 @@ final class APIDiffTests: XCTestCase {
119
116
XCTAssertFalse ( output. contains ( " 💔 API breakage: var Qux.x has been removed " ) )
120
117
}
121
118
}
122
- #else
123
- throw XCTSkip ( " Test unsupported on current platform " )
124
- #endif
125
119
}
126
120
127
121
func testFilters( ) throws {
128
- #if os(macOS)
129
- guard ( try ? Resources . default. toolchain. getSwiftAPIDigester ( ) ) != nil else {
130
- throw XCTSkip ( " swift-api-digester not available " )
131
- }
122
+ try skipIfApiDigesterUnsupported ( )
132
123
fixture ( name: " Miscellaneous/APIDiff/ " ) { prefix in
133
124
let packageRoot = prefix. appending ( component: " NonAPILibraryTargets " )
134
125
try localFileSystem. writeFileContents ( packageRoot. appending ( components: " Sources " , " Foo " , " Foo.swift " ) ) {
@@ -197,16 +188,10 @@ final class APIDiffTests: XCTestCase {
197
188
XCTAssertTrue ( stderr. contains ( " 'Exec' is not a library target " ) )
198
189
}
199
190
}
200
- #else
201
- throw XCTSkip ( " Test unsupported on current platform " )
202
- #endif
203
191
}
204
192
205
193
func testAPIDiffOfModuleWithCDependency( ) throws {
206
- #if os(macOS)
207
- guard ( try ? Resources . default. toolchain. getSwiftAPIDigester ( ) ) != nil else {
208
- throw XCTSkip ( " swift-api-digester not available " )
209
- }
194
+ try skipIfApiDigesterUnsupported ( )
210
195
fixture ( name: " Miscellaneous/APIDiff/ " ) { prefix in
211
196
let packageRoot = prefix. appending ( component: " CTargetDep " )
212
197
// Overwrite the existing decl.
@@ -239,16 +224,10 @@ final class APIDiffTests: XCTestCase {
239
224
XCTAssertTrue ( stderr. contains ( " error: 'Foo' is not a Swift language target " ) )
240
225
}
241
226
}
242
- #else
243
- throw XCTSkip ( " Test unsupported on current platform " )
244
- #endif
245
227
}
246
228
247
229
func testNoBreakingChanges( ) throws {
248
- #if os(macOS)
249
- guard ( try ? Resources . default. toolchain. getSwiftAPIDigester ( ) ) != nil else {
250
- throw XCTSkip ( " swift-api-digester not available " )
251
- }
230
+ try skipIfApiDigesterUnsupported ( )
252
231
fixture ( name: " Miscellaneous/APIDiff/ " ) { prefix in
253
232
let packageRoot = prefix. appending ( component: " Bar " )
254
233
// Introduce an API-compatible change
@@ -259,16 +238,10 @@ final class APIDiffTests: XCTestCase {
259
238
XCTAssertTrue ( output. contains ( " No breaking changes detected in Baz " ) )
260
239
XCTAssertTrue ( output. contains ( " No breaking changes detected in Qux " ) )
261
240
}
262
- #else
263
- throw XCTSkip ( " Test unsupported on current platform " )
264
- #endif
265
241
}
266
242
267
243
func testAPIDiffAfterAddingNewTarget( ) throws {
268
- #if os(macOS)
269
- guard ( try ? Resources . default. toolchain. getSwiftAPIDigester ( ) ) != nil else {
270
- throw XCTSkip ( " swift-api-digester not available " )
271
- }
244
+ try skipIfApiDigesterUnsupported ( )
272
245
fixture ( name: " Miscellaneous/APIDiff/ " ) { prefix in
273
246
let packageRoot = prefix. appending ( component: " Bar " )
274
247
try localFileSystem. createDirectory ( packageRoot. appending ( components: " Sources " , " Foo " ) )
@@ -299,16 +272,10 @@ final class APIDiffTests: XCTestCase {
299
272
XCTAssertTrue ( output. contains ( " No breaking changes detected in Qux " ) )
300
273
XCTAssertTrue ( output. contains ( " Skipping Foo because it does not exist in the baseline " ) )
301
274
}
302
- #else
303
- throw XCTSkip ( " Test unsupported on current platform " )
304
- #endif
305
275
}
306
276
307
277
func testBadTreeish( ) throws {
308
- #if os(macOS)
309
- guard ( try ? Resources . default. toolchain. getSwiftAPIDigester ( ) ) != nil else {
310
- throw XCTSkip ( " swift-api-digester not available " )
311
- }
278
+ try skipIfApiDigesterUnsupported ( )
312
279
fixture ( name: " Miscellaneous/APIDiff/ " ) { prefix in
313
280
let packageRoot = prefix. appending ( component: " Foo " )
314
281
XCTAssertThrowsError ( try execute ( [ " experimental-api-diff " , " 7.8.9 " ] , packagePath: packageRoot) ) { error in
@@ -319,8 +286,5 @@ final class APIDiffTests: XCTestCase {
319
286
XCTAssertTrue ( stderr. contains ( " error: Couldn’t check out revision ‘7.8.9’ " ) )
320
287
}
321
288
}
322
- #else
323
- throw XCTSkip ( " Test unsupported on current platform " )
324
- #endif
325
289
}
326
290
}
0 commit comments