@@ -36,7 +36,7 @@ public final class InitPackage {
36
36
37
37
public init (
38
38
packageType: PackageType ,
39
- supportedTestingLibraries: Set < BuildParameters . Testing . Library > = [ . xctest ] ,
39
+ supportedTestingLibraries: Set < BuildParameters . Testing . Library > ,
40
40
platforms: [ SupportedPlatform ] = [ ]
41
41
) {
42
42
self . packageType = packageType
@@ -186,8 +186,8 @@ public final class InitPackage {
186
186
187
187
var platforms = options. platforms
188
188
189
- // Macros and swift-testing require macOS 10.15, iOS 13, etc.
190
- if packageType == . macro || options . supportedTestingLibraries . contains ( . swiftTesting ) {
189
+ // Macros require macOS 10.15, iOS 13, etc.
190
+ if packageType == . macro {
191
191
func addIfMissing( _ newPlatform: SupportedPlatform ) {
192
192
if platforms. contains ( where: { platform in
193
193
platform. platform == newPlatform. platform
@@ -275,9 +275,6 @@ public final class InitPackage {
275
275
} else if packageType == . macro {
276
276
dependencies. append ( #".package(url: "https://github.com/swiftlang/swift-syntax.git", from: " \#( self . installedSwiftPMConfiguration. swiftSyntaxVersionForMacroTemplate. description) ")"# )
277
277
}
278
- if options. supportedTestingLibraries. contains ( . swiftTesting) {
279
- dependencies. append ( #".package(url: "https://github.com/apple/swift-testing.git", from: "0.11.0")"# )
280
- }
281
278
if !dependencies. isEmpty {
282
279
let dependencies = dependencies. map { dependency in
283
280
" \( dependency) , "
@@ -384,17 +381,7 @@ public final class InitPackage {
384
381
"""
385
382
} else {
386
383
let testTarget : String
387
- if options. supportedTestingLibraries. contains ( . swiftTesting) {
388
- testTarget = """
389
- .testTarget(
390
- name: " \( pkgname) Tests " ,
391
- dependencies: [
392
- " \( pkgname) " ,
393
- .product(name: " Testing " , package: " swift-testing " ),
394
- ]
395
- ),
396
- """
397
- } else if options. supportedTestingLibraries. contains ( . xctest) {
384
+ if !options. supportedTestingLibraries. isEmpty {
398
385
testTarget = """
399
386
.testTarget(
400
387
name: " \( pkgname) Tests " ,
@@ -687,6 +674,10 @@ public final class InitPackage {
687
674
private func writeLibraryTestsFile( _ path: AbsolutePath ) throws {
688
675
var content = " "
689
676
677
+ // XCTest is only added if it was explicitly asked for, so add tests
678
+ // for it *and* Testing if it is enabled (or just XCTest if Testing
679
+ // is explicitly disabled).
680
+
690
681
if options. supportedTestingLibraries. contains ( . swiftTesting) {
691
682
content += " import Testing \n "
692
683
}
@@ -695,20 +686,18 @@ public final class InitPackage {
695
686
}
696
687
content += " @testable import \( moduleName) \n "
697
688
698
- // Prefer swift-testing if specified, otherwise XCTest. If both are
699
- // specified, the developer is free to write tests using both
700
- // libraries, but we still only want to present a single library's
701
- // example tests.
689
+
702
690
if options. supportedTestingLibraries. contains ( . swiftTesting) {
703
691
content += """
704
692
705
- @Test func example() throws {
706
- // swift-testing Documentation
707
- // https://swiftpackageindex.com/apple/swift-testing/main/documentation/testing
693
+ @Test func example() async throws {
694
+ // Write your test here and use APIs like `#expect(...)` to check expected conditions.
708
695
}
709
696
710
697
"""
711
- } else if options. supportedTestingLibraries. contains ( . xctest) {
698
+ }
699
+
700
+ if options. supportedTestingLibraries. contains ( . xctest) {
712
701
content += """
713
702
714
703
final class \( moduleName) Tests: XCTestCase {
@@ -761,13 +750,15 @@ public final class InitPackage {
761
750
762
751
"""##
763
752
764
- // Prefer swift-testing if specified, otherwise XCTest. If both are
765
- // specified, the developer is free to write tests using both
766
- // libraries, but we still only want to present a single library's
767
- // example tests.
753
+
754
+ // XCTest is only added if it was explicitly asked for, so add tests
755
+ // for it *and* Testing if it is enabled.
756
+
768
757
if options. supportedTestingLibraries. contains ( . swiftTesting) {
769
758
// FIXME: https://github.com/swiftlang/swift-syntax/issues/2400
770
- } else if options. supportedTestingLibraries. contains ( . xctest) {
759
+ }
760
+
761
+ if options. supportedTestingLibraries. contains ( . xctest) {
771
762
content += ##"""
772
763
final class \##( moduleName) Tests: XCTestCase {
773
764
func testMacro() throws {
0 commit comments