Skip to content

Add an environment check to opt in for API diff functionality tests #3697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 31, 2021
Merged
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
53 changes: 40 additions & 13 deletions Tests/CommandsTests/APIDiffTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,16 @@ final class APIDiffTests: XCTestCase {
environment["SWIFTPM_TESTS_PACKAGECACHE"] = "1"
return try SwiftPMProduct.SwiftPackage.execute(args, packagePath: packagePath, env: environment)
}


func skipIfApiDigesterUnsupportedOrUnset() throws {
try skipIfApiDigesterUnsupported()
// The following is added to separate out the integration point testing of the API
// diff digester with SwiftPM from the functionality tests of the digester itself
guard ProcessEnv.vars["SWIFTPM_TEST_API_DIFF_OUTPUT"] == "1" else {
throw XCTSkip("Env var SWIFTPM_TEST_API_DIFF_OUTPUT must be set to test the output")
}
}

func skipIfApiDigesterUnsupported() throws {
// swift-api-digester is required to run tests.
guard (try? UserToolchain.default.getSwiftAPIDigester()) != nil else {
Expand All @@ -44,8 +53,26 @@ final class APIDiffTests: XCTestCase {
}
}

func testSimpleAPIDiff() throws {
func testInvokeAPIDiffDigester() throws {
try skipIfApiDigesterUnsupported()
fixture(name: "Miscellaneous/APIDiff/") { prefix in
let packageRoot = prefix.appending(component: "Foo")
// Overwrite the existing decl.
try localFileSystem.writeFileContents(packageRoot.appending(component: "Foo.swift")) {
$0 <<< "public let foo = 42"
}
XCTAssertThrowsError(try execute(["diagnose-api-breaking-changes", "1.2.3"], packagePath: packageRoot)) { error in
guard case SwiftPMProductError.executionFailure(error: _, output: let output, stderr: _) = error else {
XCTFail("Unexpected error")
return
}
XCTAssertFalse(output.isEmpty)
}
}
}

func testSimpleAPIDiff() throws {
try skipIfApiDigesterUnsupportedOrUnset()
fixture(name: "Miscellaneous/APIDiff/") { prefix in
let packageRoot = prefix.appending(component: "Foo")
// Overwrite the existing decl.
Expand All @@ -64,7 +91,7 @@ final class APIDiffTests: XCTestCase {
}

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

func testBreakageAllowlist() throws {
try skipIfApiDigesterUnsupported()
try skipIfApiDigesterUnsupportedOrUnset()
fixture(name: "Miscellaneous/APIDiff/") { prefix in
let packageRoot = prefix.appending(component: "Bar")
try localFileSystem.writeFileContents(packageRoot.appending(components: "Sources", "Baz", "Baz.swift")) {
Expand Down Expand Up @@ -119,7 +146,7 @@ final class APIDiffTests: XCTestCase {
}

func testCheckVendedModulesOnly() throws {
try skipIfApiDigesterUnsupported()
try skipIfApiDigesterUnsupportedOrUnset()
fixture(name: "Miscellaneous/APIDiff/") { prefix in
let packageRoot = prefix.appending(component: "NonAPILibraryTargets")
try localFileSystem.writeFileContents(packageRoot.appending(components: "Sources", "Foo", "Foo.swift")) {
Expand Down Expand Up @@ -155,7 +182,7 @@ final class APIDiffTests: XCTestCase {
}

func testFilters() throws {
try skipIfApiDigesterUnsupported()
try skipIfApiDigesterUnsupportedOrUnset()
fixture(name: "Miscellaneous/APIDiff/") { prefix in
let packageRoot = prefix.appending(component: "NonAPILibraryTargets")
try localFileSystem.writeFileContents(packageRoot.appending(components: "Sources", "Foo", "Foo.swift")) {
Expand Down Expand Up @@ -227,7 +254,7 @@ final class APIDiffTests: XCTestCase {
}

func testAPIDiffOfModuleWithCDependency() throws {
try skipIfApiDigesterUnsupported()
try skipIfApiDigesterUnsupportedOrUnset()
fixture(name: "Miscellaneous/APIDiff/") { prefix in
let packageRoot = prefix.appending(component: "CTargetDep")
// Overwrite the existing decl.
Expand Down Expand Up @@ -263,7 +290,7 @@ final class APIDiffTests: XCTestCase {
}

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

func testAPIDiffAfterAddingNewTarget() throws {
try skipIfApiDigesterUnsupported()
try skipIfApiDigesterUnsupportedOrUnset()
fixture(name: "Miscellaneous/APIDiff/") { prefix in
let packageRoot = prefix.appending(component: "Bar")
try localFileSystem.createDirectory(packageRoot.appending(components: "Sources", "Foo"))
Expand Down Expand Up @@ -311,7 +338,7 @@ final class APIDiffTests: XCTestCase {
}

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

func testBranchUpdate() throws {
try skipIfApiDigesterUnsupported()
try skipIfApiDigesterUnsupportedOrUnset()
try withTemporaryDirectory { baselineDir in
fixture(name: "Miscellaneous/APIDiff/") { prefix in
let packageRoot = prefix.appending(component: "Foo")
Expand Down Expand Up @@ -363,7 +390,7 @@ final class APIDiffTests: XCTestCase {
}

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

func testRegenerateBaseline() throws {
try skipIfApiDigesterUnsupported()
try skipIfApiDigesterUnsupportedOrUnset()
fixture(name: "Miscellaneous/APIDiff/") { prefix in
let packageRoot = prefix.appending(component: "Foo")
// Overwrite the existing decl.
Expand Down