@@ -75,63 +75,6 @@ struct SharedOptions: ParsableArguments {
75
75
/// to choose from (usually in multiroot packages).
76
76
@Option ( help: . hidden)
77
77
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
- }
135
78
}
136
79
137
80
struct TestCommandOptions : ParsableArguments {
@@ -141,6 +84,10 @@ struct TestCommandOptions: ParsableArguments {
141
84
@OptionGroup ( )
142
85
var sharedOptions : SharedOptions
143
86
87
+ /// Which testing libraries to use (and any related options.)
88
+ @OptionGroup ( )
89
+ var testLibraryOptions : TestLibraryOptions
90
+
144
91
/// If tests should run in parallel mode.
145
92
@Flag ( name: . customLong( " parallel " ) ,
146
93
inversion: . prefixedNo,
@@ -425,10 +372,10 @@ public struct SwiftTestCommand: SwiftCommand {
425
372
let command = try List . parse ( )
426
373
try command. run ( swiftCommandState)
427
374
} else {
428
- if try options. sharedOptions . enableSwiftTestingLibrarySupport ( swiftCommandState: swiftCommandState) {
375
+ if try options. testLibraryOptions . enableSwiftTestingLibrarySupport ( swiftCommandState: swiftCommandState) {
429
376
try swiftTestingRun ( swiftCommandState)
430
377
}
431
- if options. sharedOptions . enableXCTestSupport {
378
+ if options. testLibraryOptions . enableXCTestSupport {
432
379
try xctestRun ( swiftCommandState)
433
380
}
434
381
}
@@ -624,7 +571,7 @@ public struct SwiftTestCommand: SwiftCommand {
624
571
throw StringError ( " '--num-workers' must be greater than zero " )
625
572
}
626
573
627
- if !options. sharedOptions . enableXCTestSupport {
574
+ if !options. testLibraryOptions . enableXCTestSupport {
628
575
throw StringError ( " '--num-workers' is only supported when testing with XCTest " )
629
576
}
630
577
}
@@ -680,6 +627,10 @@ extension SwiftTestCommand {
680
627
@OptionGroup ( )
681
628
var sharedOptions : SharedOptions
682
629
630
+ /// Which testing libraries to use (and any related options.)
631
+ @OptionGroup ( )
632
+ var testLibraryOptions : TestLibraryOptions
633
+
683
634
// for deprecated passthrough from SwiftTestTool (parse will fail otherwise)
684
635
@Flag ( name: [ . customLong( " list-tests " ) , . customShort( " l " ) ] , help: . hidden)
685
636
var _deprecated_passthrough : Bool = false
@@ -752,10 +703,10 @@ extension SwiftTestCommand {
752
703
// MARK: - Common implementation
753
704
754
705
func run( _ swiftCommandState: SwiftCommandState ) throws {
755
- if try sharedOptions . enableSwiftTestingLibrarySupport ( swiftCommandState: swiftCommandState) {
706
+ if try testLibraryOptions . enableSwiftTestingLibrarySupport ( swiftCommandState: swiftCommandState) {
756
707
try swiftTestingRun ( swiftCommandState)
757
708
}
758
- if sharedOptions . enableXCTestSupport {
709
+ if testLibraryOptions . enableXCTestSupport {
759
710
try xctestRun ( swiftCommandState)
760
711
}
761
712
}
@@ -1327,7 +1278,7 @@ extension SwiftCommandState {
1327
1278
experimentalTestOutput: options. enableExperimentalTestOutput,
1328
1279
library: library
1329
1280
)
1330
- if try options. sharedOptions . enableSwiftTestingLibrarySupport ( swiftCommandState: self ) {
1281
+ if try options. testLibraryOptions . enableSwiftTestingLibrarySupport ( swiftCommandState: self ) {
1331
1282
result. flags. swiftCompilerFlags += [ " -DSWIFT_PM_SUPPORTS_SWIFT_TESTING " ]
1332
1283
}
1333
1284
return result
0 commit comments