@@ -4116,7 +4116,87 @@ class PackageCommandTestCase: CommandsBuildProviderTestCase {
4116
4116
// Only run the test if the environment in which we're running actually supports Swift concurrency (which the plugin APIs require).
4117
4117
try XCTSkipIf ( !UserToolchain. default. supportsSwiftConcurrency ( ) , " skipping because test environment doesn't support concurrency " )
4118
4118
4119
- try await fixtureXCTest ( name: " Miscellaneous/Plugins/PluginSuccessful/ " ) { packageDir in
4119
+ try await testWithTemporaryDirectory { tmpPath in
4120
+ // Create a sample package with a couple of plugins a other targets and products.
4121
+ let packageDir = tmpPath. appending ( components: " MyPackage " )
4122
+ try localFileSystem. createDirectory ( packageDir, recursive: true )
4123
+ try localFileSystem. writeFileContents ( packageDir. appending ( components: " Package.swift " ) , string: """
4124
+ // swift-tools-version: 5.6
4125
+ import PackageDescription
4126
+ let package = Package(
4127
+ name: " MyPackage " ,
4128
+ products: [
4129
+ .library(
4130
+ name: " MyLibrary " ,
4131
+ targets: [ " MyLibrary " ]
4132
+ ),
4133
+ .executable(
4134
+ name: " MyExecutable " ,
4135
+ targets: [ " MyExecutable " ]
4136
+ ),
4137
+ ],
4138
+ targets: [
4139
+ .target(
4140
+ name: " MyLibrary "
4141
+ ),
4142
+ .executableTarget(
4143
+ name: " MyExecutable " ,
4144
+ dependencies: [ " MyLibrary " ]
4145
+ ),
4146
+ .plugin(
4147
+ name: " MyBuildToolPlugin " ,
4148
+ capability: .buildTool()
4149
+ ),
4150
+ .plugin(
4151
+ name: " MyCommandPlugin " ,
4152
+ capability: .command(
4153
+ intent: .custom(verb: " my-build-tester " , description: " Help description " )
4154
+ )
4155
+ ),
4156
+ ]
4157
+ )
4158
+ """
4159
+ )
4160
+ let myLibraryTargetDir = packageDir. appending ( components: " Sources " , " MyLibrary " )
4161
+ try localFileSystem. createDirectory ( myLibraryTargetDir, recursive: true )
4162
+ try localFileSystem. writeFileContents ( myLibraryTargetDir. appending ( " library.swift " ) , string: """
4163
+ public func GetGreeting() -> String { return " Hello " }
4164
+ """
4165
+ )
4166
+ let myExecutableTargetDir = packageDir. appending ( components: " Sources " , " MyExecutable " )
4167
+ try localFileSystem. createDirectory ( myExecutableTargetDir, recursive: true )
4168
+ try localFileSystem. writeFileContents ( myExecutableTargetDir. appending ( " main.swift " ) , string: """
4169
+ import MyLibrary
4170
+ print( " \\ (GetGreeting()), World! " )
4171
+ """
4172
+ )
4173
+ let myBuildToolPluginTargetDir = packageDir. appending ( components: " Plugins " , " MyBuildToolPlugin " )
4174
+ try localFileSystem. createDirectory ( myBuildToolPluginTargetDir, recursive: true )
4175
+ try localFileSystem. writeFileContents ( myBuildToolPluginTargetDir. appending ( " plugin.swift " ) , string: """
4176
+ import PackagePlugin
4177
+ @main struct MyBuildToolPlugin: BuildToolPlugin {
4178
+ func createBuildCommands(
4179
+ context: PluginContext,
4180
+ target: Target
4181
+ ) throws -> [Command] {
4182
+ return []
4183
+ }
4184
+ }
4185
+ """
4186
+ )
4187
+ let myCommandPluginTargetDir = packageDir. appending ( components: " Plugins " , " MyCommandPlugin " )
4188
+ try localFileSystem. createDirectory ( myCommandPluginTargetDir, recursive: true )
4189
+ try localFileSystem. writeFileContents ( myCommandPluginTargetDir. appending ( " plugin.swift " ) , string: """
4190
+ import PackagePlugin
4191
+ @main struct MyCommandPlugin: CommandPlugin {
4192
+ func performCommand(
4193
+ context: PluginContext,
4194
+ arguments: [String]
4195
+ ) throws {
4196
+ }
4197
+ }
4198
+ """
4199
+ )
4120
4200
4121
4201
// Check that building without options compiles both plugins and that the build proceeds.
4122
4202
do {
@@ -4149,7 +4229,89 @@ class PackageCommandTestCase: CommandsBuildProviderTestCase {
4149
4229
// Only run the test if the environment in which we're running actually supports Swift concurrency (which the plugin APIs require).
4150
4230
try XCTSkipIf ( !UserToolchain. default. supportsSwiftConcurrency ( ) , " skipping because test environment doesn't support concurrency " )
4151
4231
4152
- try await fixtureXCTest ( name: " Miscellaneous/Plugins/CommandPluginUnsuccessful/ " ) { packageDir in
4232
+ try await testWithTemporaryDirectory { tmpPath in
4233
+ // Create a sample package with a couple of plugins a other targets and products.
4234
+ let packageDir = tmpPath. appending ( components: " MyPackage " )
4235
+ try localFileSystem. createDirectory ( packageDir, recursive: true )
4236
+ try localFileSystem. writeFileContents ( packageDir. appending ( components: " Package.swift " ) , string: """
4237
+ // swift-tools-version: 5.6
4238
+ import PackageDescription
4239
+ let package = Package(
4240
+ name: " MyPackage " ,
4241
+ products: [
4242
+ .library(
4243
+ name: " MyLibrary " ,
4244
+ targets: [ " MyLibrary " ]
4245
+ ),
4246
+ .executable(
4247
+ name: " MyExecutable " ,
4248
+ targets: [ " MyExecutable " ]
4249
+ ),
4250
+ ],
4251
+ targets: [
4252
+ .target(
4253
+ name: " MyLibrary "
4254
+ ),
4255
+ .executableTarget(
4256
+ name: " MyExecutable " ,
4257
+ dependencies: [ " MyLibrary " ]
4258
+ ),
4259
+ .plugin(
4260
+ name: " MyBuildToolPlugin " ,
4261
+ capability: .buildTool()
4262
+ ),
4263
+ .plugin(
4264
+ name: " MyCommandPlugin " ,
4265
+ capability: .command(
4266
+ intent: .custom(verb: " my-build-tester " , description: " Help description " )
4267
+ )
4268
+ ),
4269
+ ]
4270
+ )
4271
+ """
4272
+ )
4273
+ let myLibraryTargetDir = packageDir. appending ( components: " Sources " , " MyLibrary " )
4274
+ try localFileSystem. createDirectory ( myLibraryTargetDir, recursive: true )
4275
+ try localFileSystem. writeFileContents ( myLibraryTargetDir. appending ( " library.swift " ) , string: """
4276
+ public func GetGreeting() -> String { return " Hello " }
4277
+ """
4278
+ )
4279
+ let myExecutableTargetDir = packageDir. appending ( components: " Sources " , " MyExecutable " )
4280
+ try localFileSystem. createDirectory ( myExecutableTargetDir, recursive: true )
4281
+ try localFileSystem. writeFileContents ( myExecutableTargetDir. appending ( " main.swift " ) , string: """
4282
+ import MyLibrary
4283
+ print( " \\ (GetGreeting()), World! " )
4284
+ """
4285
+ )
4286
+ let myBuildToolPluginTargetDir = packageDir. appending ( components: " Plugins " , " MyBuildToolPlugin " )
4287
+ try localFileSystem. createDirectory ( myBuildToolPluginTargetDir, recursive: true )
4288
+ try localFileSystem. writeFileContents ( myBuildToolPluginTargetDir. appending ( " plugin.swift " ) , string: """
4289
+ import PackagePlugin
4290
+ @main struct MyBuildToolPlugin: BuildToolPlugin {
4291
+ func createBuildCommands(
4292
+ context: PluginContext,
4293
+ target: Target
4294
+ ) throws -> [Command] {
4295
+ return []
4296
+ }
4297
+ }
4298
+ """
4299
+ )
4300
+ // Deliberately break the command plugin.
4301
+ let myCommandPluginTargetDir = packageDir. appending ( components: " Plugins " , " MyCommandPlugin " )
4302
+ try localFileSystem. createDirectory ( myCommandPluginTargetDir, recursive: true )
4303
+ try localFileSystem. writeFileContents ( myCommandPluginTargetDir. appending ( " plugin.swift " ) , string: """
4304
+ import PackagePlugin
4305
+ @main struct MyCommandPlugin: CommandPlugin {
4306
+ func performCommand(
4307
+ context: PluginContext,
4308
+ arguments: [String]
4309
+ ) throws {
4310
+ this is an error
4311
+ }
4312
+ }
4313
+ """
4314
+ )
4153
4315
// Check that building stops after compiling the plugin and doesn't proceed.
4154
4316
// Run this test a number of times to try to catch any race conditions.
4155
4317
for _ in 1 ... 5 {
@@ -4296,7 +4458,7 @@ class PackageCommandSwiftBuildTests: PackageCommandTestCase {
4296
4458
}
4297
4459
4298
4460
override func testPluginCompilationBeforeBuilding( ) async throws {
4299
- try XCTSkipOnWindows ( because: " https://github.com/swiftlang/swift-package-manager/issues/8774: Unable to write file " )
4461
+ // try XCTSkipOnWindows(because: "https://github.com/swiftlang/swift-package-manager/issues/8774: Unable to write file")
4300
4462
throw XCTSkip ( " SWBINTTODO: https:4//github.com/swiftlang/swift-package-manager/issues/8977 " )
4301
4463
try await super. testPluginCompilationBeforeBuilding ( )
4302
4464
}
0 commit comments