Skip to content

Commit 17a8eb0

Browse files
authored
Fix APIDiff test suite (#3593)
* Revert "Temporarily disable failing APIDiff tests to unblock builds (#3591)" This reverts commit c5947d6. * Use supported flags to determine if APIDiff tests should run with a given toolchain
1 parent aa9ea35 commit 17a8eb0

File tree

2 files changed

+12
-43
lines changed

2 files changed

+12
-43
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ let package = Package(
259259
dependencies: ["Build", "SPMTestSupport"]),
260260
.testTarget(
261261
name: "CommandsTests",
262-
dependencies: ["swift-build", "swift-package", "swift-test", "swift-run", "Commands", "Workspace", "SPMTestSupport"]),
262+
dependencies: ["swift-build", "swift-package", "swift-test", "swift-run", "Commands", "Workspace", "SPMTestSupport", "Build"]),
263263
.testTarget(
264264
name: "WorkspaceTests",
265265
dependencies: ["Workspace", "SPMTestSupport"]),

Tests/CommandsTests/APIDiffTests.swift

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import XCTest
1212
import Foundation
1313
import TSCBasic
14+
import Build
1415
import Commands
1516
import SPMTestSupport
1617

@@ -28,20 +29,20 @@ final class APIDiffTests: XCTestCase {
2829
}
2930

3031
func skipIfApiDigesterUnsupported() throws {
31-
guard let tool = try? Resources.default.toolchain.getSwiftAPIDigester() else {
32+
// swift-api-digester is required to run tests.
33+
guard (try? Resources.default.toolchain.getSwiftAPIDigester()) != nil else {
3234
throw XCTSkip("swift-api-digester unavailable")
3335
}
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.
36+
// SwiftPM's swift-api-digester integration relies on post-5.5 bugfixes and features,
37+
// not all of which can be tested for easily. Fortunately, we can test for the
38+
// `-disable-fail-on-error` option, and any version which supports this flag
39+
// will meet the other requirements.
40+
guard SwiftTargetBuildDescription.checkSupportedFrontendFlags(flags: ["disable-fail-on-error"], fs: localFileSystem) else {
3841
throw XCTSkip("swift-api-digester is too old")
3942
}
4043
}
4144

4245
func testSimpleAPIDiff() throws {
43-
throw XCTSkip("Fix this test")
44-
4546
try skipIfApiDigesterUnsupported()
4647
fixture(name: "Miscellaneous/APIDiff/") { prefix in
4748
let packageRoot = prefix.appending(component: "Foo")
@@ -61,8 +62,6 @@ final class APIDiffTests: XCTestCase {
6162
}
6263

6364
func testMultiTargetAPIDiff() throws {
64-
throw XCTSkip("Fix this test")
65-
6665
try skipIfApiDigesterUnsupported()
6766
fixture(name: "Miscellaneous/APIDiff/") { prefix in
6867
let packageRoot = prefix.appending(component: "Bar")
@@ -87,12 +86,7 @@ final class APIDiffTests: XCTestCase {
8786
}
8887

8988
func testBreakageAllowlist() throws {
90-
throw XCTSkip("Fix this test")
91-
92-
#if os(macOS)
93-
guard (try? Resources.default.toolchain.getSwiftAPIDigester()) != nil else {
94-
throw XCTSkip("swift-api-digester not available")
95-
}
89+
try skipIfApiDigesterUnsupported()
9690
fixture(name: "Miscellaneous/APIDiff/") { prefix in
9791
let packageRoot = prefix.appending(component: "Bar")
9892
try localFileSystem.writeFileContents(packageRoot.appending(components: "Sources", "Baz", "Baz.swift")) {
@@ -120,14 +114,9 @@ final class APIDiffTests: XCTestCase {
120114
}
121115

122116
}
123-
#else
124-
throw XCTSkip("Test unsupported on current platform")
125-
#endif
126117
}
127118

128119
func testCheckVendedModulesOnly() throws {
129-
throw XCTSkip("Fix this test")
130-
131120
try skipIfApiDigesterUnsupported()
132121
fixture(name: "Miscellaneous/APIDiff/") { prefix in
133122
let packageRoot = prefix.appending(component: "NonAPILibraryTargets")
@@ -164,8 +153,6 @@ final class APIDiffTests: XCTestCase {
164153
}
165154

166155
func testFilters() throws {
167-
throw XCTSkip("Fix this test")
168-
169156
try skipIfApiDigesterUnsupported()
170157
fixture(name: "Miscellaneous/APIDiff/") { prefix in
171158
let packageRoot = prefix.appending(component: "NonAPILibraryTargets")
@@ -238,8 +225,6 @@ final class APIDiffTests: XCTestCase {
238225
}
239226

240227
func testAPIDiffOfModuleWithCDependency() throws {
241-
throw XCTSkip("Fix this test")
242-
243228
try skipIfApiDigesterUnsupported()
244229
fixture(name: "Miscellaneous/APIDiff/") { prefix in
245230
let packageRoot = prefix.appending(component: "CTargetDep")
@@ -338,12 +323,7 @@ final class APIDiffTests: XCTestCase {
338323
}
339324

340325
func testBaselineDirOverride() throws {
341-
throw XCTSkip("Fix this test")
342-
343-
#if os(macOS)
344-
guard (try? Resources.default.toolchain.getSwiftAPIDigester()) != nil else {
345-
throw XCTSkip("swift-api-digester not available")
346-
}
326+
try skipIfApiDigesterUnsupported()
347327
fixture(name: "Miscellaneous/APIDiff/") { prefix in
348328
let packageRoot = prefix.appending(component: "Foo")
349329
// Overwrite the existing decl.
@@ -365,18 +345,10 @@ final class APIDiffTests: XCTestCase {
365345
XCTAssertTrue(localFileSystem.exists(baselineDir.appending(components: "1.2.3", "Foo.json")))
366346
}
367347
}
368-
#else
369-
throw XCTSkip("Test unsupported on current platform")
370-
#endif
371348
}
372349

373350
func testRegenerateBaseline() throws {
374-
throw XCTSkip("Fix this test")
375-
376-
#if os(macOS)
377-
guard (try? Resources.default.toolchain.getSwiftAPIDigester()) != nil else {
378-
throw XCTSkip("swift-api-digester not available")
379-
}
351+
try skipIfApiDigesterUnsupported()
380352
fixture(name: "Miscellaneous/APIDiff/") { prefix in
381353
let packageRoot = prefix.appending(component: "Foo")
382354
// Overwrite the existing decl.
@@ -406,8 +378,5 @@ final class APIDiffTests: XCTestCase {
406378
XCTAssertNotEqual((try! localFileSystem.readFileContents(fooBaselinePath)).description, "Old Baseline")
407379
}
408380
}
409-
#else
410-
throw XCTSkip("Test unsupported on current platform")
411-
#endif
412381
}
413382
}

0 commit comments

Comments
 (0)