@@ -75,63 +75,6 @@ struct SharedOptions: ParsableArguments {
7575 /// to choose from (usually in multiroot packages).
7676 @Option ( help: . hidden)
7777 var testProduct : String ?
78-
79- /// Whether to enable support for XCTest.
80- @Flag ( name: . customLong( " xctest " ) ,
81- inversion: . prefixedEnableDisable,
82- help: " Enable support for XCTest " )
83- var enableXCTestSupport : Bool = true
84-
85- /// Storage for whether to enable support for swift-testing.
86- @Flag ( name: . customLong( " experimental-swift-testing " ) ,
87- inversion: . prefixedEnableDisable,
88- help: " Enable experimental support for swift-testing " )
89- var _enableSwiftTestingLibrarySupport : Bool ?
90-
91- /// Whether to enable support for swift-testing.
92- func enableSwiftTestingLibrarySupport( swiftCommandState: SwiftCommandState ) throws -> Bool {
93- // Honor the user's explicit command-line selection, if any.
94- if let callerSuppliedValue = _enableSwiftTestingLibrarySupport {
95- return callerSuppliedValue
96- }
97-
98- // If the active package has a dependency on swift-testing, automatically enable support for it so that extra steps are not needed.
99- let workspace = try swiftCommandState. getActiveWorkspace ( )
100- let root = try swiftCommandState. getWorkspaceRoot ( )
101- let rootManifests = try temp_await {
102- workspace. loadRootManifests (
103- packages: root. packages,
104- observabilityScope: swiftCommandState. observabilityScope,
105- completion: $0
106- )
107- }
108-
109- // Is swift-testing among the dependencies of the package being built?
110- // If so, enable support.
111- let isEnabledByDependency = rootManifests. values. lazy
112- . flatMap ( \. dependencies)
113- . map ( \. identity)
114- . map ( String . init ( describing: ) )
115- . contains ( " swift-testing " )
116- if isEnabledByDependency {
117- swiftCommandState. observabilityScope. emit ( debug: " Enabling swift-testing support due to its presence as a package dependency. " )
118- return true
119- }
120-
121- // Is swift-testing the package being built itself (unlikely)? If so,
122- // enable support.
123- let isEnabledByName = root. packages. lazy
124- . map ( PackageIdentity . init ( path: ) )
125- . map ( String . init ( describing: ) )
126- . contains ( " swift-testing " )
127- if isEnabledByName {
128- swiftCommandState. observabilityScope. emit ( debug: " Enabling swift-testing support because it is a root package. " )
129- return true
130- }
131-
132- // Default to disabled since swift-testing is experimental (opt-in.)
133- return false
134- }
13578}
13679
13780struct TestCommandOptions : ParsableArguments {
@@ -141,6 +84,10 @@ struct TestCommandOptions: ParsableArguments {
14184 @OptionGroup ( )
14285 var sharedOptions : SharedOptions
14386
87+ /// Which testing libraries to use (and any related options.)
88+ @OptionGroup ( )
89+ var testLibraryOptions : TestLibraryOptions
90+
14491 /// If tests should run in parallel mode.
14592 @Flag ( name: . customLong( " parallel " ) ,
14693 inversion: . prefixedNo,
@@ -425,10 +372,10 @@ public struct SwiftTestCommand: SwiftCommand {
425372 let command = try List . parse ( )
426373 try command. run ( swiftCommandState)
427374 } else {
428- if try options. sharedOptions . enableSwiftTestingLibrarySupport ( swiftCommandState: swiftCommandState) {
375+ if try options. testLibraryOptions . enableSwiftTestingLibrarySupport ( swiftCommandState: swiftCommandState) {
429376 try swiftTestingRun ( swiftCommandState)
430377 }
431- if options. sharedOptions . enableXCTestSupport {
378+ if options. testLibraryOptions . enableXCTestSupport {
432379 try xctestRun ( swiftCommandState)
433380 }
434381 }
@@ -624,7 +571,7 @@ public struct SwiftTestCommand: SwiftCommand {
624571 throw StringError ( " '--num-workers' must be greater than zero " )
625572 }
626573
627- if !options. sharedOptions . enableXCTestSupport {
574+ if !options. testLibraryOptions . enableXCTestSupport {
628575 throw StringError ( " '--num-workers' is only supported when testing with XCTest " )
629576 }
630577 }
@@ -680,6 +627,10 @@ extension SwiftTestCommand {
680627 @OptionGroup ( )
681628 var sharedOptions : SharedOptions
682629
630+ /// Which testing libraries to use (and any related options.)
631+ @OptionGroup ( )
632+ var testLibraryOptions : TestLibraryOptions
633+
683634 // for deprecated passthrough from SwiftTestTool (parse will fail otherwise)
684635 @Flag ( name: [ . customLong( " list-tests " ) , . customShort( " l " ) ] , help: . hidden)
685636 var _deprecated_passthrough : Bool = false
@@ -752,10 +703,10 @@ extension SwiftTestCommand {
752703 // MARK: - Common implementation
753704
754705 func run( _ swiftCommandState: SwiftCommandState ) throws {
755- if try sharedOptions . enableSwiftTestingLibrarySupport ( swiftCommandState: swiftCommandState) {
706+ if try testLibraryOptions . enableSwiftTestingLibrarySupport ( swiftCommandState: swiftCommandState) {
756707 try swiftTestingRun ( swiftCommandState)
757708 }
758- if sharedOptions . enableXCTestSupport {
709+ if testLibraryOptions . enableXCTestSupport {
759710 try xctestRun ( swiftCommandState)
760711 }
761712 }
@@ -1327,7 +1278,7 @@ extension SwiftCommandState {
13271278 experimentalTestOutput: options. enableExperimentalTestOutput,
13281279 library: library
13291280 )
1330- if try options. sharedOptions . enableSwiftTestingLibrarySupport ( swiftCommandState: self ) {
1281+ if try options. testLibraryOptions . enableSwiftTestingLibrarySupport ( swiftCommandState: self ) {
13311282 result. flags. swiftCompilerFlags += [ " -DSWIFT_PM_SUPPORTS_SWIFT_TESTING " ]
13321283 }
13331284 return result
0 commit comments