@@ -39,25 +39,27 @@ final class APIDiffTests: CommandsTestCase {
39
39
40
40
func skipIfApiDigesterUnsupportedOrUnset( ) throws {
41
41
try skipIfApiDigesterUnsupported ( )
42
- // The following is added to separate out the integration point testing of the API
43
- // diff digester with SwiftPM from the functionality tests of the digester itself
44
- guard Environment . current [ " SWIFTPM_TEST_API_DIFF_OUTPUT " ] == " 1 " else {
45
- throw XCTSkip ( " Env var SWIFTPM_TEST_API_DIFF_OUTPUT must be set to test the output " )
46
- }
42
+ // Opt out from testing the API diff if necessary.
43
+ // TODO: Cleanup after March 2025.
44
+ // The opt-in/opt-out mechanism doesn't seem to be used.
45
+ // It is kept around for abundance of caution. If "why is it needed"
46
+ // not identified by March 2025, then it is OK to remove it.
47
+ try XCTSkipIf (
48
+ Environment . current [ " SWIFTPM_TEST_API_DIFF_OUTPUT " ] == " 0 " ,
49
+ " Env var SWIFTPM_TEST_API_DIFF_OUTPUT is set to skip the API diff tests. "
50
+ )
47
51
}
48
52
49
53
func skipIfApiDigesterUnsupported( ) throws {
50
54
// swift-api-digester is required to run tests.
51
55
guard ( try ? UserToolchain . default. getSwiftAPIDigester ( ) ) != nil else {
52
56
throw XCTSkip ( " swift-api-digester unavailable " )
53
57
}
54
- // SwiftPM's swift-api-digester integration relies on post-5.5 bugfixes and features,
55
- // not all of which can be tested for easily. Fortunately, we can test for the
56
- // `-disable-fail-on-error` option, and any version which supports this flag
57
- // will meet the other requirements.
58
- guard DriverSupport . checkSupportedFrontendFlags ( flags: [ " disable-fail-on-error " ] , toolchain: try UserToolchain . default, fileSystem: localFileSystem) else {
59
- throw XCTSkip ( " swift-api-digester is too old " )
60
- }
58
+ // The tests rely on swift-api-digester post-5.5 version and are certain
59
+ // to work with Swift compiler v6.0 and later.
60
+ #if compiler(<6.0)
61
+ throw XCTSkip ( " Skipping because test requires at least Swift compiler v6.0 " )
62
+ #endif
61
63
}
62
64
63
65
func testInvokeAPIDiffDigester( ) async throws {
@@ -165,18 +167,13 @@ final class APIDiffTests: CommandsTestCase {
165
167
string: " public class Qux<T, U> { private let x = 1 } "
166
168
)
167
169
await XCTAssertThrowsCommandExecutionError ( try await execute ( [ " diagnose-api-breaking-changes " , " 1.2.3 " ] , packagePath: packageRoot) ) { error in
168
- XCTAssertMatch ( error. stdout, . contains( " 1 breaking change detected in Foo " ) )
169
- XCTAssertMatch ( error. stdout, . contains( " 💔 API breakage: struct Foo has been removed " ) )
170
- XCTAssertMatch ( error. stdout, . contains( " 2 breaking changes detected in Bar " ) )
171
- XCTAssertMatch ( error. stdout, . contains( " 💔 API breakage: import Baz has been removed " ) )
172
- XCTAssertMatch ( error. stdout, . contains( " 💔 API breakage: func bar() has been removed " ) )
173
- XCTAssertMatch ( error. stdout, . contains( " 1 breaking change detected in Baz " ) )
174
- XCTAssertMatch ( error. stdout, . contains( " 💔 API breakage: enumelement Baz.b has been added as a new enum case " ) )
170
+ XCTAssertMatch ( error. stdout, . contains( " 💔 API breakage " ) )
171
+ XCTAssertMatch ( error. stdout, . regex( " \\ d+ breaking change(s?) detected in Foo " ) )
172
+ XCTAssertMatch ( error. stdout, . regex( " \\ d+ breaking change(s?) detected in Bar " ) )
173
+ XCTAssertMatch ( error. stdout, . regex( " \\ d+ breaking change(s?) detected in Baz " ) )
175
174
176
175
// Qux is not part of a library product, so any API changes should be ignored
177
- XCTAssertNoMatch ( error. stdout, . contains( " 2 breaking changes detected in Qux " ) )
178
- XCTAssertNoMatch ( error. stdout, . contains( " 💔 API breakage: class Qux has generic signature change from <T> to <T, U> " ) )
179
- XCTAssertNoMatch ( error. stdout, . contains( " 💔 API breakage: var Qux.x has been removed " ) )
176
+ XCTAssertNoMatch ( error. stdout, . contains( " Qux " ) )
180
177
}
181
178
}
182
179
}
@@ -204,33 +201,26 @@ final class APIDiffTests: CommandsTestCase {
204
201
await XCTAssertThrowsCommandExecutionError (
205
202
try await execute ( [ " diagnose-api-breaking-changes " , " 1.2.3 " , " --products " , " One " , " --targets " , " Bar " ] , packagePath: packageRoot)
206
203
) { error in
207
- XCTAssertMatch ( error. stdout, . contains( " 1 breaking change detected in Foo " ) )
208
- XCTAssertMatch ( error. stdout, . contains( " 💔 API breakage: struct Foo has been removed " ) )
209
- XCTAssertMatch ( error. stdout, . contains( " 2 breaking changes detected in Bar " ) )
210
- XCTAssertMatch ( error. stdout, . contains( " 💔 API breakage: import Baz has been removed " ) )
211
- XCTAssertMatch ( error. stdout, . contains( " 💔 API breakage: func bar() has been removed " ) )
204
+ XCTAssertMatch ( error. stdout, . contains( " 💔 API breakage " ) )
205
+ XCTAssertMatch ( error. stdout, . regex( " \\ d+ breaking change(s?) detected in Foo " ) )
206
+ XCTAssertMatch ( error. stdout, . regex( " \\ d+ breaking change(s?) detected in Bar " ) )
212
207
213
- XCTAssertNoMatch ( error. stdout, . contains( " 1 breaking change detected in Baz " ) )
214
- XCTAssertNoMatch ( error. stdout, . contains( " 💔 API breakage: enumelement Baz.b has been added as a new enum case " ) )
215
- XCTAssertNoMatch ( error. stdout, . contains( " 2 breaking changes detected in Qux " ) )
216
- XCTAssertNoMatch ( error. stdout, . contains( " 💔 API breakage: class Qux has generic signature change from <T> to <T, U> " ) )
217
- XCTAssertNoMatch ( error. stdout, . contains( " 💔 API breakage: var Qux.x has been removed " ) )
208
+ // Baz and Qux are not included in the filter, so any API changes should be ignored.
209
+ XCTAssertNoMatch ( error. stdout, . contains( " Baz " ) )
210
+ XCTAssertNoMatch ( error. stdout, . contains( " Qux " ) )
218
211
}
219
212
220
213
// Diff a target which didn't have a baseline generated as part of the first invocation
221
214
await XCTAssertThrowsCommandExecutionError (
222
215
try await execute ( [ " diagnose-api-breaking-changes " , " 1.2.3 " , " --targets " , " Baz " ] , packagePath: packageRoot)
223
216
) { error in
224
- XCTAssertMatch ( error. stdout, . contains( " 1 breaking change detected in Baz " ) )
225
- XCTAssertMatch ( error. stdout, . contains ( " 💔 API breakage: enumelement Baz.b has been added as a new enum case " ) )
217
+ XCTAssertMatch ( error. stdout, . contains( " 💔 API breakage " ) )
218
+ XCTAssertMatch ( error. stdout, . regex ( " \\ d+ breaking change(s?) detected in Baz " ) )
226
219
227
- XCTAssertNoMatch ( error. stdout, . contains( " 1 breaking change detected in Foo " ) )
228
- XCTAssertNoMatch ( error. stdout, . contains( " 💔 API breakage: struct Foo has been removed " ) )
229
- XCTAssertNoMatch ( error. stdout, . contains( " 1 breaking change detected in Bar " ) )
230
- XCTAssertNoMatch ( error. stdout, . contains( " 💔 API breakage: func bar() has been removed " ) )
231
- XCTAssertNoMatch ( error. stdout, . contains( " 2 breaking changes detected in Qux " ) )
232
- XCTAssertNoMatch ( error. stdout, . contains( " 💔 API breakage: class Qux has generic signature change from <T> to <T, U> " ) )
233
- XCTAssertNoMatch ( error. stdout, . contains( " 💔 API breakage: var Qux.x has been removed " ) )
220
+ // Only Baz is included, we should not see any other API changes.
221
+ XCTAssertNoMatch ( error. stdout, . contains( " Foo " ) )
222
+ XCTAssertNoMatch ( error. stdout, . contains( " Bar " ) )
223
+ XCTAssertNoMatch ( error. stdout, . contains( " Qux " ) )
234
224
}
235
225
236
226
// Test diagnostics
0 commit comments