Skip to content

Unblock tests by skipping if concurrency is not supported #5845

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
Oct 26, 2022
Merged
Show file tree
Hide file tree
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
68 changes: 68 additions & 0 deletions Tests/CommandsTests/PackageToolTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2554,4 +2554,72 @@ final class PackageToolTests: CommandsTestCase {
}
}
}

func testSinglePluginTarget() throws {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to a different file (same content except the test name) and added XCTSkipIf line

// Only run the test if the environment in which we're running actually supports Swift concurrency (which the plugin APIs require).
try XCTSkipIf(!UserToolchain.default.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency")

try testWithTemporaryDirectory { tmpPath in
// Create a sample package with a library target and a plugin.
let packageDir = tmpPath.appending(components: "MyPackage")
try localFileSystem.createDirectory(packageDir, recursive: true)
try localFileSystem.writeFileContents(packageDir.appending(component: "Package.swift"), string: """
// swift-tools-version: 5.7
import PackageDescription
let package = Package(
name: "MyPackage",
products: [
.plugin(name: "Foo", targets: ["Foo"])
],
dependencies: [
],
targets: [
.plugin(
name: "Foo",
capability: .command(
intent: .custom(verb: "Foo", description: "Plugin example"),
permissions: []
)
)
]
)
""")

let myPluginTargetDir = packageDir.appending(components: "Plugins", "Foo")
try localFileSystem.createDirectory(myPluginTargetDir, recursive: true)
try localFileSystem.writeFileContents(myPluginTargetDir.appending(component: "plugin.swift"), string: """
import PackagePlugin
@main struct FooPlugin: BuildToolPlugin {
func createBuildCommands(
context: PluginContext,
target: Target
) throws -> [Command] { }
}
""")

// Load a workspace from the package.
let observability = ObservabilitySystem.makeForTesting()
let workspace = try Workspace(
fileSystem: localFileSystem,
forRootPackage: packageDir,
customManifestLoader: ManifestLoader(toolchain: UserToolchain.default),
delegate: MockWorkspaceDelegate()
)

// Load the root manifest.
let rootInput = PackageGraphRootInput(packages: [packageDir], dependencies: [])
let rootManifests = try tsc_await {
workspace.loadRootManifests(
packages: rootInput.packages,
observabilityScope: observability.topScope,
completion: $0
)
}
XCTAssert(rootManifests.count == 1, "\(rootManifests)")

// Load the package graph.
let _ = try workspace.loadPackageGraph(rootInput: rootInput, observabilityScope: observability.topScope)
XCTAssertNoDiagnostics(observability.diagnostics)
}
}
}
68 changes: 3 additions & 65 deletions Tests/SPMBuildCoreTests/PluginInvocationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,9 @@ class PluginInvocationTests: XCTestCase {
}

func testPrebuildPluginShouldNotUseExecTarget() throws {
// Only run the test if the environment in which we're running actually supports Swift concurrency (which the plugin APIs require).
try XCTSkipIf(!UserToolchain.default.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency")

try testWithTemporaryDirectory { tmpPath in
// Create a sample package with a library target and a plugin.
let packageDir = tmpPath.appending(components: "mypkg")
Expand Down Expand Up @@ -720,69 +723,4 @@ class PluginInvocationTests: XCTestCase {
}
}
}

func testShouldNotRequireNonPluginTarget() throws {
try testWithTemporaryDirectory { tmpPath in
// Create a sample package with a library target and a plugin.
let packageDir = tmpPath.appending(components: "MyPackage")
try localFileSystem.createDirectory(packageDir, recursive: true)
try localFileSystem.writeFileContents(packageDir.appending(component: "Package.swift"), string: """
// swift-tools-version: 5.7
import PackageDescription
let package = Package(
name: "MyPackage",
products: [
.plugin(name: "Foo", targets: ["Foo"])
],
dependencies: [
],
targets: [
.plugin(
name: "Foo",
capability: .command(
intent: .custom(verb: "Foo", description: "Plugin example"),
permissions: []
)
)
]
)
""")

let myPluginTargetDir = packageDir.appending(components: "Plugins", "Foo")
try localFileSystem.createDirectory(myPluginTargetDir, recursive: true)
try localFileSystem.writeFileContents(myPluginTargetDir.appending(component: "plugin.swift"), string: """
import PackagePlugin
@main struct FooPlugin: BuildToolPlugin {
func createBuildCommands(
context: PluginContext,
target: Target
) throws -> [Command] { }
}
""")

// Load a workspace from the package.
let observability = ObservabilitySystem.makeForTesting()
let workspace = try Workspace(
fileSystem: localFileSystem,
forRootPackage: packageDir,
customManifestLoader: ManifestLoader(toolchain: UserToolchain.default),
delegate: MockWorkspaceDelegate()
)

// Load the root manifest.
let rootInput = PackageGraphRootInput(packages: [packageDir], dependencies: [])
let rootManifests = try tsc_await {
workspace.loadRootManifests(
packages: rootInput.packages,
observabilityScope: observability.topScope,
completion: $0
)
}
XCTAssert(rootManifests.count == 1, "\(rootManifests)")

// Load the package graph.
let _ = try workspace.loadPackageGraph(rootInput: rootInput, observabilityScope: observability.topScope)
XCTAssertNoDiagnostics(observability.diagnostics)
}
}
}