Skip to content

Commit d52267a

Browse files
authored
Unblock tests by skipping if concurrency is not supported (#5845)
Resolves rdar://101582542
1 parent 1c68725 commit d52267a

File tree

2 files changed

+71
-65
lines changed

2 files changed

+71
-65
lines changed

Tests/CommandsTests/PackageToolTests.swift

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2554,4 +2554,72 @@ final class PackageToolTests: CommandsTestCase {
25542554
}
25552555
}
25562556
}
2557+
2558+
func testSinglePluginTarget() throws {
2559+
// Only run the test if the environment in which we're running actually supports Swift concurrency (which the plugin APIs require).
2560+
try XCTSkipIf(!UserToolchain.default.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency")
2561+
2562+
try testWithTemporaryDirectory { tmpPath in
2563+
// Create a sample package with a library target and a plugin.
2564+
let packageDir = tmpPath.appending(components: "MyPackage")
2565+
try localFileSystem.createDirectory(packageDir, recursive: true)
2566+
try localFileSystem.writeFileContents(packageDir.appending(component: "Package.swift"), string: """
2567+
// swift-tools-version: 5.7
2568+
import PackageDescription
2569+
let package = Package(
2570+
name: "MyPackage",
2571+
products: [
2572+
.plugin(name: "Foo", targets: ["Foo"])
2573+
],
2574+
dependencies: [
2575+
],
2576+
targets: [
2577+
.plugin(
2578+
name: "Foo",
2579+
capability: .command(
2580+
intent: .custom(verb: "Foo", description: "Plugin example"),
2581+
permissions: []
2582+
)
2583+
)
2584+
]
2585+
)
2586+
""")
2587+
2588+
let myPluginTargetDir = packageDir.appending(components: "Plugins", "Foo")
2589+
try localFileSystem.createDirectory(myPluginTargetDir, recursive: true)
2590+
try localFileSystem.writeFileContents(myPluginTargetDir.appending(component: "plugin.swift"), string: """
2591+
import PackagePlugin
2592+
@main struct FooPlugin: BuildToolPlugin {
2593+
func createBuildCommands(
2594+
context: PluginContext,
2595+
target: Target
2596+
) throws -> [Command] { }
2597+
}
2598+
""")
2599+
2600+
// Load a workspace from the package.
2601+
let observability = ObservabilitySystem.makeForTesting()
2602+
let workspace = try Workspace(
2603+
fileSystem: localFileSystem,
2604+
forRootPackage: packageDir,
2605+
customManifestLoader: ManifestLoader(toolchain: UserToolchain.default),
2606+
delegate: MockWorkspaceDelegate()
2607+
)
2608+
2609+
// Load the root manifest.
2610+
let rootInput = PackageGraphRootInput(packages: [packageDir], dependencies: [])
2611+
let rootManifests = try tsc_await {
2612+
workspace.loadRootManifests(
2613+
packages: rootInput.packages,
2614+
observabilityScope: observability.topScope,
2615+
completion: $0
2616+
)
2617+
}
2618+
XCTAssert(rootManifests.count == 1, "\(rootManifests)")
2619+
2620+
// Load the package graph.
2621+
let _ = try workspace.loadPackageGraph(rootInput: rootInput, observabilityScope: observability.topScope)
2622+
XCTAssertNoDiagnostics(observability.diagnostics)
2623+
}
2624+
}
25572625
}

Tests/SPMBuildCoreTests/PluginInvocationTests.swift

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,9 @@ class PluginInvocationTests: XCTestCase {
585585
}
586586

587587
func testPrebuildPluginShouldNotUseExecTarget() throws {
588+
// Only run the test if the environment in which we're running actually supports Swift concurrency (which the plugin APIs require).
589+
try XCTSkipIf(!UserToolchain.default.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency")
590+
588591
try testWithTemporaryDirectory { tmpPath in
589592
// Create a sample package with a library target and a plugin.
590593
let packageDir = tmpPath.appending(components: "mypkg")
@@ -720,69 +723,4 @@ class PluginInvocationTests: XCTestCase {
720723
}
721724
}
722725
}
723-
724-
func testShouldNotRequireNonPluginTarget() throws {
725-
try testWithTemporaryDirectory { tmpPath in
726-
// Create a sample package with a library target and a plugin.
727-
let packageDir = tmpPath.appending(components: "MyPackage")
728-
try localFileSystem.createDirectory(packageDir, recursive: true)
729-
try localFileSystem.writeFileContents(packageDir.appending(component: "Package.swift"), string: """
730-
// swift-tools-version: 5.7
731-
import PackageDescription
732-
let package = Package(
733-
name: "MyPackage",
734-
products: [
735-
.plugin(name: "Foo", targets: ["Foo"])
736-
],
737-
dependencies: [
738-
],
739-
targets: [
740-
.plugin(
741-
name: "Foo",
742-
capability: .command(
743-
intent: .custom(verb: "Foo", description: "Plugin example"),
744-
permissions: []
745-
)
746-
)
747-
]
748-
)
749-
""")
750-
751-
let myPluginTargetDir = packageDir.appending(components: "Plugins", "Foo")
752-
try localFileSystem.createDirectory(myPluginTargetDir, recursive: true)
753-
try localFileSystem.writeFileContents(myPluginTargetDir.appending(component: "plugin.swift"), string: """
754-
import PackagePlugin
755-
@main struct FooPlugin: BuildToolPlugin {
756-
func createBuildCommands(
757-
context: PluginContext,
758-
target: Target
759-
) throws -> [Command] { }
760-
}
761-
""")
762-
763-
// Load a workspace from the package.
764-
let observability = ObservabilitySystem.makeForTesting()
765-
let workspace = try Workspace(
766-
fileSystem: localFileSystem,
767-
forRootPackage: packageDir,
768-
customManifestLoader: ManifestLoader(toolchain: UserToolchain.default),
769-
delegate: MockWorkspaceDelegate()
770-
)
771-
772-
// Load the root manifest.
773-
let rootInput = PackageGraphRootInput(packages: [packageDir], dependencies: [])
774-
let rootManifests = try tsc_await {
775-
workspace.loadRootManifests(
776-
packages: rootInput.packages,
777-
observabilityScope: observability.topScope,
778-
completion: $0
779-
)
780-
}
781-
XCTAssert(rootManifests.count == 1, "\(rootManifests)")
782-
783-
// Load the package graph.
784-
let _ = try workspace.loadPackageGraph(rootInput: rootInput, observabilityScope: observability.topScope)
785-
XCTAssertNoDiagnostics(observability.diagnostics)
786-
}
787-
}
788726
}

0 commit comments

Comments
 (0)