Skip to content

[APIDiff] Enable tests on non-Darwin #3519

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
Jul 1, 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
76 changes: 20 additions & 56 deletions Tests/CommandsTests/APIDiffTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,20 @@ final class APIDiffTests: XCTestCase {
return try SwiftPMProduct.SwiftPackage.execute(args, packagePath: packagePath, env: environment)
}

func skipIfApiDigesterUnsupported() throws {
guard let tool = try? Resources.default.toolchain.getSwiftAPIDigester() else {
throw XCTSkip("swift-api-digester unavailable")
}
guard localFileSystem.isSymlink(tool) else {
Copy link
Contributor

@tomerd tomerd May 29, 2021

Choose a reason for hiding this comment

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

this seems odd. no better way to tell? cc @abertelrud

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, this is fairly subtle and won't work in the general case. Is there a -version flag with which it could be invoked and then a more robust check could be made?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

swift-api-digester is part of the frontend now, so unfortunately there's no version number to check for until "Swift Next" gets an official version number

// The version of Swift with a supported swift-api-digester doesn't have
// a version number yet, so use whether or not the tool is a symlink to
// determine if it's from a recent snapshot.
throw XCTSkip("swift-api-digester is too old")
}
}

func testSimpleAPIDiff() throws {
#if os(macOS)
guard (try? Resources.default.toolchain.getSwiftAPIDigester()) != nil else {
throw XCTSkip("swift-api-digester not available")
}
try skipIfApiDigesterUnsupported()
fixture(name: "Miscellaneous/APIDiff/") { prefix in
let packageRoot = prefix.appending(component: "Foo")
// Overwrite the existing decl.
Expand All @@ -47,16 +56,10 @@ final class APIDiffTests: XCTestCase {
XCTAssertTrue(output.contains("💔 API breakage: func foo() has been removed"))
}
}
#else
throw XCTSkip("Test unsupported on current platform")
#endif
}

func testMultiTargetAPIDiff() throws {
#if os(macOS)
guard (try? Resources.default.toolchain.getSwiftAPIDigester()) != nil else {
throw XCTSkip("swift-api-digester not available")
}
try skipIfApiDigesterUnsupported()
fixture(name: "Miscellaneous/APIDiff/") { prefix in
let packageRoot = prefix.appending(component: "Bar")
try localFileSystem.writeFileContents(packageRoot.appending(components: "Sources", "Baz", "Baz.swift")) {
Expand All @@ -77,16 +80,10 @@ final class APIDiffTests: XCTestCase {
XCTAssertTrue(output.contains("💔 API breakage: func bar() has been removed"))
}
}
#else
throw XCTSkip("Test unsupported on current platform")
#endif
}

func testCheckVendedModulesOnly() throws {
#if os(macOS)
guard (try? Resources.default.toolchain.getSwiftAPIDigester()) != nil else {
throw XCTSkip("swift-api-digester not available")
}
try skipIfApiDigesterUnsupported()
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 @@ -119,16 +116,10 @@ final class APIDiffTests: XCTestCase {
XCTAssertFalse(output.contains("💔 API breakage: var Qux.x has been removed"))
}
}
#else
throw XCTSkip("Test unsupported on current platform")
#endif
}

func testFilters() throws {
#if os(macOS)
guard (try? Resources.default.toolchain.getSwiftAPIDigester()) != nil else {
throw XCTSkip("swift-api-digester not available")
}
try skipIfApiDigesterUnsupported()
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 @@ -197,16 +188,10 @@ final class APIDiffTests: XCTestCase {
XCTAssertTrue(stderr.contains("'Exec' is not a library target"))
}
}
#else
throw XCTSkip("Test unsupported on current platform")
#endif
}

func testAPIDiffOfModuleWithCDependency() throws {
#if os(macOS)
guard (try? Resources.default.toolchain.getSwiftAPIDigester()) != nil else {
throw XCTSkip("swift-api-digester not available")
}
try skipIfApiDigesterUnsupported()
fixture(name: "Miscellaneous/APIDiff/") { prefix in
let packageRoot = prefix.appending(component: "CTargetDep")
// Overwrite the existing decl.
Expand Down Expand Up @@ -239,16 +224,10 @@ final class APIDiffTests: XCTestCase {
XCTAssertTrue(stderr.contains("error: 'Foo' is not a Swift language target"))
}
}
#else
throw XCTSkip("Test unsupported on current platform")
#endif
}

func testNoBreakingChanges() throws {
#if os(macOS)
guard (try? Resources.default.toolchain.getSwiftAPIDigester()) != nil else {
throw XCTSkip("swift-api-digester not available")
}
try skipIfApiDigesterUnsupported()
fixture(name: "Miscellaneous/APIDiff/") { prefix in
let packageRoot = prefix.appending(component: "Bar")
// Introduce an API-compatible change
Expand All @@ -259,16 +238,10 @@ final class APIDiffTests: XCTestCase {
XCTAssertTrue(output.contains("No breaking changes detected in Baz"))
XCTAssertTrue(output.contains("No breaking changes detected in Qux"))
}
#else
throw XCTSkip("Test unsupported on current platform")
#endif
}

func testAPIDiffAfterAddingNewTarget() throws {
#if os(macOS)
guard (try? Resources.default.toolchain.getSwiftAPIDigester()) != nil else {
throw XCTSkip("swift-api-digester not available")
}
try skipIfApiDigesterUnsupported()
fixture(name: "Miscellaneous/APIDiff/") { prefix in
let packageRoot = prefix.appending(component: "Bar")
try localFileSystem.createDirectory(packageRoot.appending(components: "Sources", "Foo"))
Expand Down Expand Up @@ -299,16 +272,10 @@ final class APIDiffTests: XCTestCase {
XCTAssertTrue(output.contains("No breaking changes detected in Qux"))
XCTAssertTrue(output.contains("Skipping Foo because it does not exist in the baseline"))
}
#else
throw XCTSkip("Test unsupported on current platform")
#endif
}

func testBadTreeish() throws {
#if os(macOS)
guard (try? Resources.default.toolchain.getSwiftAPIDigester()) != nil else {
throw XCTSkip("swift-api-digester not available")
}
try skipIfApiDigesterUnsupported()
fixture(name: "Miscellaneous/APIDiff/") { prefix in
let packageRoot = prefix.appending(component: "Foo")
XCTAssertThrowsError(try execute(["experimental-api-diff", "7.8.9"], packagePath: packageRoot)) { error in
Expand All @@ -319,8 +286,5 @@ final class APIDiffTests: XCTestCase {
XCTAssertTrue(stderr.contains("error: Couldn’t check out revision ‘7.8.9’"))
}
}
#else
throw XCTSkip("Test unsupported on current platform")
#endif
}
}