Skip to content

Commit fabdb40

Browse files
committed
[APIDiff] Enable tests on non-Darwin
1 parent b0e0388 commit fabdb40

File tree

1 file changed

+20
-56
lines changed

1 file changed

+20
-56
lines changed

Tests/CommandsTests/APIDiffTests.swift

Lines changed: 20 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,20 @@ final class APIDiffTests: XCTestCase {
2727
return try SwiftPMProduct.SwiftPackage.execute(args, packagePath: packagePath, env: environment)
2828
}
2929

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+
3042
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()
3544
fixture(name: "Miscellaneous/APIDiff/") { prefix in
3645
let packageRoot = prefix.appending(component: "Foo")
3746
// Overwrite the existing decl.
@@ -47,16 +56,10 @@ final class APIDiffTests: XCTestCase {
4756
XCTAssertTrue(output.contains("💔 API breakage: func foo() has been removed"))
4857
}
4958
}
50-
#else
51-
throw XCTSkip("Test unsupported on current platform")
52-
#endif
5359
}
5460

5561
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()
6063
fixture(name: "Miscellaneous/APIDiff/") { prefix in
6164
let packageRoot = prefix.appending(component: "Bar")
6265
try localFileSystem.writeFileContents(packageRoot.appending(components: "Sources", "Baz", "Baz.swift")) {
@@ -77,16 +80,10 @@ final class APIDiffTests: XCTestCase {
7780
XCTAssertTrue(output.contains("💔 API breakage: func bar() has been removed"))
7881
}
7982
}
80-
#else
81-
throw XCTSkip("Test unsupported on current platform")
82-
#endif
8383
}
8484

8585
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()
9087
fixture(name: "Miscellaneous/APIDiff/") { prefix in
9188
let packageRoot = prefix.appending(component: "NonAPILibraryTargets")
9289
try localFileSystem.writeFileContents(packageRoot.appending(components: "Sources", "Foo", "Foo.swift")) {
@@ -119,16 +116,10 @@ final class APIDiffTests: XCTestCase {
119116
XCTAssertFalse(output.contains("💔 API breakage: var Qux.x has been removed"))
120117
}
121118
}
122-
#else
123-
throw XCTSkip("Test unsupported on current platform")
124-
#endif
125119
}
126120

127121
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()
132123
fixture(name: "Miscellaneous/APIDiff/") { prefix in
133124
let packageRoot = prefix.appending(component: "NonAPILibraryTargets")
134125
try localFileSystem.writeFileContents(packageRoot.appending(components: "Sources", "Foo", "Foo.swift")) {
@@ -197,16 +188,10 @@ final class APIDiffTests: XCTestCase {
197188
XCTAssertTrue(stderr.contains("'Exec' is not a library target"))
198189
}
199190
}
200-
#else
201-
throw XCTSkip("Test unsupported on current platform")
202-
#endif
203191
}
204192

205193
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()
210195
fixture(name: "Miscellaneous/APIDiff/") { prefix in
211196
let packageRoot = prefix.appending(component: "CTargetDep")
212197
// Overwrite the existing decl.
@@ -239,16 +224,10 @@ final class APIDiffTests: XCTestCase {
239224
XCTAssertTrue(stderr.contains("error: 'Foo' is not a Swift language target"))
240225
}
241226
}
242-
#else
243-
throw XCTSkip("Test unsupported on current platform")
244-
#endif
245227
}
246228

247229
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()
252231
fixture(name: "Miscellaneous/APIDiff/") { prefix in
253232
let packageRoot = prefix.appending(component: "Bar")
254233
// Introduce an API-compatible change
@@ -259,16 +238,10 @@ final class APIDiffTests: XCTestCase {
259238
XCTAssertTrue(output.contains("No breaking changes detected in Baz"))
260239
XCTAssertTrue(output.contains("No breaking changes detected in Qux"))
261240
}
262-
#else
263-
throw XCTSkip("Test unsupported on current platform")
264-
#endif
265241
}
266242

267243
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()
272245
fixture(name: "Miscellaneous/APIDiff/") { prefix in
273246
let packageRoot = prefix.appending(component: "Bar")
274247
try localFileSystem.createDirectory(packageRoot.appending(components: "Sources", "Foo"))
@@ -299,16 +272,10 @@ final class APIDiffTests: XCTestCase {
299272
XCTAssertTrue(output.contains("No breaking changes detected in Qux"))
300273
XCTAssertTrue(output.contains("Skipping Foo because it does not exist in the baseline"))
301274
}
302-
#else
303-
throw XCTSkip("Test unsupported on current platform")
304-
#endif
305275
}
306276

307277
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()
312279
fixture(name: "Miscellaneous/APIDiff/") { prefix in
313280
let packageRoot = prefix.appending(component: "Foo")
314281
XCTAssertThrowsError(try execute(["experimental-api-diff", "7.8.9"], packagePath: packageRoot)) { error in
@@ -319,8 +286,5 @@ final class APIDiffTests: XCTestCase {
319286
XCTAssertTrue(stderr.contains("error: Couldn’t check out revision ‘7.8.9’"))
320287
}
321288
}
322-
#else
323-
throw XCTSkip("Test unsupported on current platform")
324-
#endif
325289
}
326290
}

0 commit comments

Comments
 (0)