@@ -256,8 +256,10 @@ public struct SwiftTestCommand: AsyncSwiftCommand {
256
256
var results = [ TestRunner . Result] ( )
257
257
258
258
// Run XCTest.
259
- if options. testLibraryOptions. isEnabled ( . xctest) {
260
- // validate XCTest available on darwin based systems
259
+ if options. testLibraryOptions. isEnabled ( . xctest, swiftCommandState: swiftCommandState) {
260
+ // Validate XCTest available on Darwin-based systems. If it's not available and we're hitting this code
261
+ // path, that means the developer must have explicitly passed --enable-xctest (or the toolchain is
262
+ // corrupt, I suppose.)
261
263
let toolchain = try swiftCommandState. getTargetToolchain ( )
262
264
if case let . unsupported( reason) = try swiftCommandState. getHostToolchain ( ) . swiftSDK. xctestSupport {
263
265
if let reason {
@@ -278,7 +280,7 @@ public struct SwiftTestCommand: AsyncSwiftCommand {
278
280
swiftCommandState: swiftCommandState,
279
281
library: . xctest
280
282
)
281
- if result == . success, let testCount , testCount == 0 {
283
+ if result == . success, testCount == 0 {
282
284
results. append ( . noMatchingTests)
283
285
} else {
284
286
results. append ( result)
@@ -324,9 +326,9 @@ public struct SwiftTestCommand: AsyncSwiftCommand {
324
326
}
325
327
326
328
// Run Swift Testing (parallel or not, it has a single entry point.)
327
- if options. testLibraryOptions. isEnabled ( . swiftTesting) {
329
+ if options. testLibraryOptions. isEnabled ( . swiftTesting, swiftCommandState : swiftCommandState ) {
328
330
lazy var testEntryPointPath = testProducts. lazy. compactMap ( \. testEntryPointPath) . first
329
- if options. testLibraryOptions. isExplicitlyEnabled ( . swiftTesting) || testEntryPointPath == nil {
331
+ if options. testLibraryOptions. isExplicitlyEnabled ( . swiftTesting, swiftCommandState : swiftCommandState ) || testEntryPointPath == nil {
330
332
results. append (
331
333
try await runTestProducts (
332
334
testProducts,
@@ -412,7 +414,7 @@ public struct SwiftTestCommand: AsyncSwiftCommand {
412
414
public func run( _ swiftCommandState: SwiftCommandState ) async throws {
413
415
do {
414
416
// Validate commands arguments
415
- try self . validateArguments ( observabilityScope : swiftCommandState. observabilityScope )
417
+ try self . validateArguments ( swiftCommandState : swiftCommandState)
416
418
} catch {
417
419
swiftCommandState. observabilityScope. emit ( error)
418
420
throw ExitCode . failure
@@ -466,7 +468,7 @@ public struct SwiftTestCommand: AsyncSwiftCommand {
466
468
}
467
469
additionalArguments += commandLineArguments
468
470
469
- if var xunitPath = options. xUnitOutput, options. testLibraryOptions. isEnabled ( . xctest) {
471
+ if var xunitPath = options. xUnitOutput, options. testLibraryOptions. isEnabled ( . xctest, swiftCommandState : swiftCommandState ) {
470
472
// We are running Swift Testing, XCTest is also running in this session, and an xUnit path
471
473
// was specified. Make sure we don't stomp on XCTest's XML output by having Swift Testing
472
474
// write to a different path.
@@ -634,7 +636,7 @@ public struct SwiftTestCommand: AsyncSwiftCommand {
634
636
/// Private function that validates the commands arguments
635
637
///
636
638
/// - Throws: if a command argument is invalid
637
- private func validateArguments( observabilityScope : ObservabilityScope ) throws {
639
+ private func validateArguments( swiftCommandState : SwiftCommandState ) throws {
638
640
// Validation for --num-workers.
639
641
if let workers = options. numberOfWorkers {
640
642
@@ -649,13 +651,13 @@ public struct SwiftTestCommand: AsyncSwiftCommand {
649
651
throw StringError ( " '--num-workers' must be greater than zero " )
650
652
}
651
653
652
- guard options. testLibraryOptions. isEnabled ( . xctest) else {
654
+ guard options. testLibraryOptions. isEnabled ( . xctest, swiftCommandState : swiftCommandState ) else {
653
655
throw StringError ( " '--num-workers' is only supported when testing with XCTest " )
654
656
}
655
657
}
656
658
657
659
if options. _deprecated_shouldListTests {
658
- observabilityScope. emit ( warning: " '--list-tests' option is deprecated; use 'swift test list' instead " )
660
+ swiftCommandState . observabilityScope. emit ( warning: " '--list-tests' option is deprecated; use 'swift test list' instead " )
659
661
}
660
662
}
661
663
@@ -739,7 +741,7 @@ extension SwiftTestCommand {
739
741
library: . swiftTesting
740
742
)
741
743
742
- if testLibraryOptions. isEnabled ( . xctest) {
744
+ if testLibraryOptions. isEnabled ( . xctest, swiftCommandState : swiftCommandState ) {
743
745
let testSuites = try TestingSupport . getTestSuites (
744
746
in: testProducts,
745
747
swiftCommandState: swiftCommandState,
@@ -755,9 +757,9 @@ extension SwiftTestCommand {
755
757
}
756
758
}
757
759
758
- if testLibraryOptions. isEnabled ( . swiftTesting) {
760
+ if testLibraryOptions. isEnabled ( . swiftTesting, swiftCommandState : swiftCommandState ) {
759
761
lazy var testEntryPointPath = testProducts. lazy. compactMap ( \. testEntryPointPath) . first
760
- if testLibraryOptions. isExplicitlyEnabled ( . swiftTesting) || testEntryPointPath == nil {
762
+ if testLibraryOptions. isExplicitlyEnabled ( . swiftTesting, swiftCommandState : swiftCommandState ) || testEntryPointPath == nil {
761
763
let additionalArguments = [ " --list-tests " ] + CommandLine. arguments. dropFirst ( )
762
764
let runner = TestRunner (
763
765
bundlePaths: testProducts. map ( \. binaryPath) ,
0 commit comments