Skip to content

Commit f6bf6b3

Browse files
authored
Add an environment check to opt in for API diff functionality tests (#3697)
1 parent c115e14 commit f6bf6b3

File tree

1 file changed

+40
-13
lines changed

1 file changed

+40
-13
lines changed

Tests/CommandsTests/APIDiffTests.swift

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,16 @@ final class APIDiffTests: XCTestCase {
2929
environment["SWIFTPM_TESTS_PACKAGECACHE"] = "1"
3030
return try SwiftPMProduct.SwiftPackage.execute(args, packagePath: packagePath, env: environment)
3131
}
32-
32+
33+
func skipIfApiDigesterUnsupportedOrUnset() throws {
34+
try skipIfApiDigesterUnsupported()
35+
// The following is added to separate out the integration point testing of the API
36+
// diff digester with SwiftPM from the functionality tests of the digester itself
37+
guard ProcessEnv.vars["SWIFTPM_TEST_API_DIFF_OUTPUT"] == "1" else {
38+
throw XCTSkip("Env var SWIFTPM_TEST_API_DIFF_OUTPUT must be set to test the output")
39+
}
40+
}
41+
3342
func skipIfApiDigesterUnsupported() throws {
3443
// swift-api-digester is required to run tests.
3544
guard (try? UserToolchain.default.getSwiftAPIDigester()) != nil else {
@@ -44,8 +53,26 @@ final class APIDiffTests: XCTestCase {
4453
}
4554
}
4655

47-
func testSimpleAPIDiff() throws {
56+
func testInvokeAPIDiffDigester() throws {
4857
try skipIfApiDigesterUnsupported()
58+
fixture(name: "Miscellaneous/APIDiff/") { prefix in
59+
let packageRoot = prefix.appending(component: "Foo")
60+
// Overwrite the existing decl.
61+
try localFileSystem.writeFileContents(packageRoot.appending(component: "Foo.swift")) {
62+
$0 <<< "public let foo = 42"
63+
}
64+
XCTAssertThrowsError(try execute(["diagnose-api-breaking-changes", "1.2.3"], packagePath: packageRoot)) { error in
65+
guard case SwiftPMProductError.executionFailure(error: _, output: let output, stderr: _) = error else {
66+
XCTFail("Unexpected error")
67+
return
68+
}
69+
XCTAssertFalse(output.isEmpty)
70+
}
71+
}
72+
}
73+
74+
func testSimpleAPIDiff() throws {
75+
try skipIfApiDigesterUnsupportedOrUnset()
4976
fixture(name: "Miscellaneous/APIDiff/") { prefix in
5077
let packageRoot = prefix.appending(component: "Foo")
5178
// Overwrite the existing decl.
@@ -64,7 +91,7 @@ final class APIDiffTests: XCTestCase {
6491
}
6592

6693
func testMultiTargetAPIDiff() throws {
67-
try skipIfApiDigesterUnsupported()
94+
try skipIfApiDigesterUnsupportedOrUnset()
6895
fixture(name: "Miscellaneous/APIDiff/") { prefix in
6996
let packageRoot = prefix.appending(component: "Bar")
7097
try localFileSystem.writeFileContents(packageRoot.appending(components: "Sources", "Baz", "Baz.swift")) {
@@ -88,7 +115,7 @@ final class APIDiffTests: XCTestCase {
88115
}
89116

90117
func testBreakageAllowlist() throws {
91-
try skipIfApiDigesterUnsupported()
118+
try skipIfApiDigesterUnsupportedOrUnset()
92119
fixture(name: "Miscellaneous/APIDiff/") { prefix in
93120
let packageRoot = prefix.appending(component: "Bar")
94121
try localFileSystem.writeFileContents(packageRoot.appending(components: "Sources", "Baz", "Baz.swift")) {
@@ -119,7 +146,7 @@ final class APIDiffTests: XCTestCase {
119146
}
120147

121148
func testCheckVendedModulesOnly() throws {
122-
try skipIfApiDigesterUnsupported()
149+
try skipIfApiDigesterUnsupportedOrUnset()
123150
fixture(name: "Miscellaneous/APIDiff/") { prefix in
124151
let packageRoot = prefix.appending(component: "NonAPILibraryTargets")
125152
try localFileSystem.writeFileContents(packageRoot.appending(components: "Sources", "Foo", "Foo.swift")) {
@@ -155,7 +182,7 @@ final class APIDiffTests: XCTestCase {
155182
}
156183

157184
func testFilters() throws {
158-
try skipIfApiDigesterUnsupported()
185+
try skipIfApiDigesterUnsupportedOrUnset()
159186
fixture(name: "Miscellaneous/APIDiff/") { prefix in
160187
let packageRoot = prefix.appending(component: "NonAPILibraryTargets")
161188
try localFileSystem.writeFileContents(packageRoot.appending(components: "Sources", "Foo", "Foo.swift")) {
@@ -227,7 +254,7 @@ final class APIDiffTests: XCTestCase {
227254
}
228255

229256
func testAPIDiffOfModuleWithCDependency() throws {
230-
try skipIfApiDigesterUnsupported()
257+
try skipIfApiDigesterUnsupportedOrUnset()
231258
fixture(name: "Miscellaneous/APIDiff/") { prefix in
232259
let packageRoot = prefix.appending(component: "CTargetDep")
233260
// Overwrite the existing decl.
@@ -263,7 +290,7 @@ final class APIDiffTests: XCTestCase {
263290
}
264291

265292
func testNoBreakingChanges() throws {
266-
try skipIfApiDigesterUnsupported()
293+
try skipIfApiDigesterUnsupportedOrUnset()
267294
fixture(name: "Miscellaneous/APIDiff/") { prefix in
268295
let packageRoot = prefix.appending(component: "Bar")
269296
// Introduce an API-compatible change
@@ -277,7 +304,7 @@ final class APIDiffTests: XCTestCase {
277304
}
278305

279306
func testAPIDiffAfterAddingNewTarget() throws {
280-
try skipIfApiDigesterUnsupported()
307+
try skipIfApiDigesterUnsupportedOrUnset()
281308
fixture(name: "Miscellaneous/APIDiff/") { prefix in
282309
let packageRoot = prefix.appending(component: "Bar")
283310
try localFileSystem.createDirectory(packageRoot.appending(components: "Sources", "Foo"))
@@ -311,7 +338,7 @@ final class APIDiffTests: XCTestCase {
311338
}
312339

313340
func testBadTreeish() throws {
314-
try skipIfApiDigesterUnsupported()
341+
try skipIfApiDigesterUnsupportedOrUnset()
315342
fixture(name: "Miscellaneous/APIDiff/") { prefix in
316343
let packageRoot = prefix.appending(component: "Foo")
317344
XCTAssertThrowsError(try execute(["diagnose-api-breaking-changes", "7.8.9"], packagePath: packageRoot)) { error in
@@ -325,7 +352,7 @@ final class APIDiffTests: XCTestCase {
325352
}
326353

327354
func testBranchUpdate() throws {
328-
try skipIfApiDigesterUnsupported()
355+
try skipIfApiDigesterUnsupportedOrUnset()
329356
try withTemporaryDirectory { baselineDir in
330357
fixture(name: "Miscellaneous/APIDiff/") { prefix in
331358
let packageRoot = prefix.appending(component: "Foo")
@@ -363,7 +390,7 @@ final class APIDiffTests: XCTestCase {
363390
}
364391

365392
func testBaselineDirOverride() throws {
366-
try skipIfApiDigesterUnsupported()
393+
try skipIfApiDigesterUnsupportedOrUnset()
367394
fixture(name: "Miscellaneous/APIDiff/") { prefix in
368395
let packageRoot = prefix.appending(component: "Foo")
369396
// Overwrite the existing decl.
@@ -390,7 +417,7 @@ final class APIDiffTests: XCTestCase {
390417
}
391418

392419
func testRegenerateBaseline() throws {
393-
try skipIfApiDigesterUnsupported()
420+
try skipIfApiDigesterUnsupportedOrUnset()
394421
fixture(name: "Miscellaneous/APIDiff/") { prefix in
395422
let packageRoot = prefix.appending(component: "Foo")
396423
// Overwrite the existing decl.

0 commit comments

Comments
 (0)