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