@@ -36,7 +36,7 @@ public final class InitPackage {
3636
3737 public init (
3838 packageType: PackageType ,
39- supportedTestingLibraries: Set < BuildParameters . Testing . Library > = [ . xctest ] ,
39+ supportedTestingLibraries: Set < BuildParameters . Testing . Library > ,
4040 platforms: [ SupportedPlatform ] = [ ]
4141 ) {
4242 self . packageType = packageType
@@ -186,8 +186,8 @@ public final class InitPackage {
186186
187187 var platforms = options. platforms
188188
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 {
191191 func addIfMissing( _ newPlatform: SupportedPlatform ) {
192192 if platforms. contains ( where: { platform in
193193 platform. platform == newPlatform. platform
@@ -275,9 +275,6 @@ public final class InitPackage {
275275 } else if packageType == . macro {
276276 dependencies. append ( #".package(url: "https://github.com/swiftlang/swift-syntax.git", from: " \#( self . installedSwiftPMConfiguration. swiftSyntaxVersionForMacroTemplate. description) ")"# )
277277 }
278- if options. supportedTestingLibraries. contains ( . swiftTesting) {
279- dependencies. append ( #".package(url: "https://github.com/apple/swift-testing.git", from: "0.11.0")"# )
280- }
281278 if !dependencies. isEmpty {
282279 let dependencies = dependencies. map { dependency in
283280 " \( dependency) , "
@@ -384,17 +381,7 @@ public final class InitPackage {
384381 """
385382 } else {
386383 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 {
398385 testTarget = """
399386 .testTarget(
400387 name: " \( pkgname) Tests " ,
@@ -687,6 +674,10 @@ public final class InitPackage {
687674 private func writeLibraryTestsFile( _ path: AbsolutePath ) throws {
688675 var content = " "
689676
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+
690681 if options. supportedTestingLibraries. contains ( . swiftTesting) {
691682 content += " import Testing \n "
692683 }
@@ -695,20 +686,18 @@ public final class InitPackage {
695686 }
696687 content += " @testable import \( moduleName) \n "
697688
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+
702690 if options. supportedTestingLibraries. contains ( . swiftTesting) {
703691 content += """
704692
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.
708695 }
709696
710697 """
711- } else if options. supportedTestingLibraries. contains ( . xctest) {
698+ }
699+
700+ if options. supportedTestingLibraries. contains ( . xctest) {
712701 content += """
713702
714703 final class \( moduleName) Tests: XCTestCase {
@@ -761,13 +750,15 @@ public final class InitPackage {
761750
762751 """##
763752
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+
768757 if options. supportedTestingLibraries. contains ( . swiftTesting) {
769758 // FIXME: https://github.com/swiftlang/swift-syntax/issues/2400
770- } else if options. supportedTestingLibraries. contains ( . xctest) {
759+ }
760+
761+ if options. supportedTestingLibraries. contains ( . xctest) {
771762 content += ##"""
772763 final class \##( moduleName) Tests: XCTestCase {
773764 func testMacro() throws {
0 commit comments