@@ -300,20 +300,44 @@ public final class InitPackage {
300
300
301
301
"""
302
302
if packageType == . executable {
303
+ let testTarget : String
304
+ if !options. supportedTestingLibraries. isEmpty {
305
+ testTarget = """
306
+ .testTarget(
307
+ name: " \( pkgname) Tests " ,
308
+ dependencies: [ " \( pkgname) " ]
309
+ ),
310
+ """
311
+ } else {
312
+ testTarget = " "
313
+ }
303
314
param += """
304
315
.executableTarget(
305
316
name: " \( pkgname) "
306
317
),
318
+ \( testTarget)
307
319
]
308
320
"""
309
321
} else if packageType == . tool {
322
+ let testTarget : String
323
+ if !options. supportedTestingLibraries. isEmpty {
324
+ testTarget = """
325
+ .testTarget(
326
+ name: " \( pkgname) Tests " ,
327
+ dependencies: [ " \( pkgname) " ]
328
+ ),
329
+ """
330
+ } else {
331
+ testTarget = " "
332
+ }
310
333
param += """
311
334
.executableTarget(
312
335
name: " \( pkgname) " ,
313
336
dependencies: [
314
337
.product(name: " ArgumentParser " , package: " swift-argument-parser " ),
315
338
]
316
339
),
340
+ \( testTarget)
317
341
]
318
342
"""
319
343
} else if packageType == . buildToolPlugin {
@@ -337,22 +361,8 @@ public final class InitPackage {
337
361
"""
338
362
} else if packageType == . macro {
339
363
let testTarget : String
340
- if options. supportedTestingLibraries. contains ( . swiftTesting) {
341
- testTarget = """
342
-
343
- // A test target used to develop the macro implementation.
344
- .testTarget(
345
- name: " \( pkgname) Tests " ,
346
- dependencies: [
347
- " \( pkgname) Macros " ,
348
- .product(name: " SwiftSyntaxMacrosTestSupport " , package: " swift-syntax " ),
349
- .product(name: " Testing " , package: " swift-testing " ),
350
- ]
351
- ),
352
- """
353
- } else if options. supportedTestingLibraries. contains ( . xctest) {
364
+ if !options. supportedTestingLibraries. isEmpty {
354
365
testTarget = """
355
-
356
366
// A test target used to develop the macro implementation.
357
367
.testTarget(
358
368
name: " \( pkgname) Tests " ,
@@ -661,7 +671,7 @@ public final class InitPackage {
661
671
}
662
672
663
673
switch packageType {
664
- case . empty, . executable , . tool , . buildToolPlugin, . commandPlugin: return
674
+ case . empty, . buildToolPlugin, . commandPlugin: return
665
675
default : break
666
676
}
667
677
let tests = destinationPath. appending ( " Tests " )
@@ -874,8 +884,8 @@ public final class InitPackage {
874
884
875
885
let testClassFile = try AbsolutePath ( validating: " \( moduleName) Tests.swift " , relativeTo: testModule)
876
886
switch packageType {
877
- case . empty, . buildToolPlugin, . commandPlugin, . executable , . tool : break
878
- case . library:
887
+ case . empty, . buildToolPlugin, . commandPlugin: break
888
+ case . library, . executable , . tool :
879
889
try writeLibraryTestsFile ( testClassFile)
880
890
case . macro:
881
891
try writeMacroTestsFile ( testClassFile)
0 commit comments