Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 30 additions & 61 deletions Tests/CommandsTests/APIDiffTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,11 @@ struct APIDiffTests {
string: "public class Qux<T, U> { private let x = 1 }"
)
await expectThrowsCommandExecutionError(try await execute(["diagnose-api-breaking-changes", "1.2.3"], packagePath: packageRoot, buildSystem: buildSystem)) { error in
withKnownIssue {
#expect(error.stdout.contains("2 breaking changes detected in Qux"))
#expect(error.stdout.contains("💔 API breakage: class Qux has generic signature change from <T> to <T, U>"))
#expect(error.stdout.contains("💔 API breakage: var Qux.x has been removed"))
#expect(error.stdout.contains("1 breaking change detected in Baz"))
#expect(error.stdout.contains("💔 API breakage: func bar() has been removed"))
} when: {
buildSystem == .swiftbuild && ProcessInfo.isHostAmazonLinux2()
}
#expect(error.stdout.contains("2 breaking changes detected in Qux"))
#expect(error.stdout.contains("💔 API breakage: class Qux has generic signature change from <T> to <T, U>"))
#expect(error.stdout.contains("💔 API breakage: var Qux.x has been removed"))
#expect(error.stdout.contains("1 breaking change detected in Baz"))
#expect(error.stdout.contains("💔 API breakage: func bar() has been removed"))
}
}
}
Expand Down Expand Up @@ -142,16 +138,11 @@ struct APIDiffTests {
packagePath: packageRoot, buildSystem: buildSystem)
) { error in
#expect(!error.stdout.contains("💔 API breakage: class Qux has generic signature change from <T> to <T, U>"))
withKnownIssue {
#expect(error.stdout.contains("1 breaking change detected in Qux"))
#expect(error.stdout.contains("💔 API breakage: var Qux.x has been removed"))
#expect(error.stdout.contains("1 breaking change detected in Baz"))
#expect(error.stdout.contains("💔 API breakage: func bar() has been removed"))
} when: {
buildSystem == .swiftbuild && ProcessInfo.isHostAmazonLinux2()
}
#expect(error.stdout.contains("1 breaking change detected in Qux"))
#expect(error.stdout.contains("💔 API breakage: var Qux.x has been removed"))
#expect(error.stdout.contains("1 breaking change detected in Baz"))
#expect(error.stdout.contains("💔 API breakage: func bar() has been removed"))
}

}
}

Expand Down Expand Up @@ -180,16 +171,11 @@ struct APIDiffTests {
string: "public class Qux<T, U> { private let x = 1 }"
)
try await expectThrowsCommandExecutionError(try await execute(["diagnose-api-breaking-changes", "1.2.3"], packagePath: packageRoot, buildSystem: buildSystem)) { error in
try withKnownIssue {
#expect(error.stdout.contains("💔 API breakage"))
let regex = try Regex("\\d+ breaking change(s?) detected in Foo")
#expect(error.stdout.contains(regex))
#expect(error.stdout.contains(regex))
#expect(error.stdout.contains(regex))
} when: {
buildSystem == .swiftbuild && ProcessInfo.isHostAmazonLinux2()
}

#expect(error.stdout.contains("💔 API breakage"))
let regex = try Regex("\\d+ breaking change(s?) detected in Foo")
#expect(error.stdout.contains(regex))
#expect(error.stdout.contains(regex))
#expect(error.stdout.contains(regex))
// Qux is not part of a library product, so any API changes should be ignored
#expect(!error.stdout.contains("Qux"))
}
Expand Down Expand Up @@ -226,18 +212,10 @@ struct APIDiffTests {
try await expectThrowsCommandExecutionError(
try await execute(["diagnose-api-breaking-changes", "1.2.3", "--products", "One", "--targets", "Bar"], packagePath: packageRoot, buildSystem: buildSystem)
) { error in
withKnownIssue {
#expect(error.stdout.contains("💔 API breakage"))
} when: {
buildSystem == .swiftbuild && ProcessInfo.isHostAmazonLinux2()
}
#expect(error.stdout.contains("💔 API breakage"))
let regex = try Regex("\\d+ breaking change(s?) detected in Foo")

withKnownIssue {
#expect(error.stdout.contains(regex))
} when: {
buildSystem == .swiftbuild && ProcessInfo.isHostAmazonLinux2()
}
#expect(error.stdout.contains(regex))

// Baz and Qux are not included in the filter, so any API changes should be ignored.
#expect(!error.stdout.contains("Baz"))
Expand All @@ -248,14 +226,9 @@ struct APIDiffTests {
try await expectThrowsCommandExecutionError(
try await execute(["diagnose-api-breaking-changes", "1.2.3", "--targets", "Baz"], packagePath: packageRoot, buildSystem: buildSystem)
) { error in
try withKnownIssue {
#expect(error.stdout.contains("💔 API breakage"))
let regex = try Regex("\\d+ breaking change(s?) detected in Baz")
#expect(error.stdout.contains(regex))
} when: {
buildSystem == .swiftbuild && ProcessInfo.isHostAmazonLinux2()
}

#expect(error.stdout.contains("💔 API breakage"))
let regex = try Regex("\\d+ breaking change(s?) detected in Baz")
#expect(error.stdout.contains(regex))
// Only Baz is included, we should not see any other API changes.
#expect(!error.stdout.contains("Foo"))
#expect(!error.stdout.contains("Bar"))
Expand All @@ -279,7 +252,7 @@ struct APIDiffTests {
.tags(
.Feature.Command.Run,
),
.requiresAPIDigester,
.requiresAPIDigester,
arguments: SupportedBuildSystemOnAllPlatforms
)
func testAPIDiffOfModuleWithCDependency(buildSystem: BuildSystemProvider.Kind) async throws {
Expand Down Expand Up @@ -341,20 +314,16 @@ struct APIDiffTests {
arguments: SupportedBuildSystemOnAllPlatforms,
)
func testNoBreakingChanges(buildSystem: BuildSystemProvider.Kind) async throws {
try await withKnownIssue {
try await fixture(name: "Miscellaneous/APIDiff/") { fixturePath in
let packageRoot = fixturePath.appending("Bar")
// Introduce an API-compatible change
try localFileSystem.writeFileContents(
packageRoot.appending(components: "Sources", "Baz", "Baz.swift"),
string: "public func bar() -> Int { 100 }"
)
let (output, _) = try await execute(["diagnose-api-breaking-changes", "1.2.3"], packagePath: packageRoot, buildSystem: buildSystem)
#expect(output.contains("No breaking changes detected in Baz"))
#expect(output.contains("No breaking changes detected in Qux"))
}
} when : {
buildSystem == .swiftbuild && ProcessInfo.isHostAmazonLinux2()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: is the "isAmazonLinux2()" function used anywhere else? Can we remove it if not?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd leave it for now, in case we need it again in the near future.

try await fixture(name: "Miscellaneous/APIDiff/") { fixturePath in
let packageRoot = fixturePath.appending("Bar")
// Introduce an API-compatible change
try localFileSystem.writeFileContents(
packageRoot.appending(components: "Sources", "Baz", "Baz.swift"),
string: "public func bar() -> Int { 100 }"
)
let (output, _) = try await execute(["diagnose-api-breaking-changes", "1.2.3"], packagePath: packageRoot, buildSystem: buildSystem)
#expect(output.contains("No breaking changes detected in Baz"))
#expect(output.contains("No breaking changes detected in Qux"))
}
}

Expand Down