@@ -237,53 +237,47 @@ public struct SwiftTestTool: SwiftCommand {
237
237
let tests = try testSuites
238
238
. filteredTests ( specifier: options. testCaseSpecifier)
239
239
. skippedTests ( specifier: options. skippedTests ( fileSystem: swiftTool. fileSystem) )
240
- var testResults = [ ParallelTestRunner . TestResult] ( )
241
240
242
241
// If there were no matches, emit a warning and exit.
243
242
if tests. isEmpty {
244
243
swiftTool. observabilityScope. emit ( . noMatchingTests)
245
- } else {
246
- // Clean out the code coverage directory that may contain stale
247
- // profraw files from a previous run of the code coverage tool.
248
- if self . options. enableCodeCoverage {
249
- try swiftTool. fileSystem. removeFileTree ( buildParameters. codeCovPath)
250
- }
244
+ try generateXUnitOutputIfRequested ( for: [ ] , swiftTool: swiftTool)
245
+ return
246
+ }
251
247
252
- // Run the tests using the parallel runner.
253
- let runner = ParallelTestRunner (
254
- bundlePaths: testProducts. map { $0. bundlePath } ,
255
- cancellator: swiftTool. cancellator,
256
- toolchain: toolchain,
257
- numJobs: options. numberOfWorkers ?? ProcessInfo . processInfo. activeProcessorCount,
258
- buildOptions: globalOptions. build,
259
- buildParameters: buildParameters,
260
- shouldOutputSuccess: swiftTool. logLevel <= . info,
261
- observabilityScope: swiftTool. observabilityScope
262
- )
263
-
264
- testResults = try runner. run ( tests)
265
-
266
- // process code Coverage if request
267
- if self . options. enableCodeCoverage, runner. ranSuccessfully {
268
- try processCodeCoverage ( testProducts, swiftTool: swiftTool, library: . xctest)
269
- }
248
+ // Clean out the code coverage directory that may contain stale
249
+ // profraw files from a previous run of the code coverage tool.
250
+ if self . options. enableCodeCoverage {
251
+ try swiftTool. fileSystem. removeFileTree ( buildParameters. codeCovPath)
252
+ }
270
253
271
- if !runner. ranSuccessfully {
272
- swiftTool. executionStatus = . failure
273
- }
254
+ // Run the tests using the parallel runner.
255
+ let runner = ParallelTestRunner (
256
+ bundlePaths: testProducts. map { $0. bundlePath } ,
257
+ cancellator: swiftTool. cancellator,
258
+ toolchain: toolchain,
259
+ numJobs: options. numberOfWorkers ?? ProcessInfo . processInfo. activeProcessorCount,
260
+ buildOptions: globalOptions. build,
261
+ buildParameters: buildParameters,
262
+ shouldOutputSuccess: swiftTool. logLevel <= . info,
263
+ observabilityScope: swiftTool. observabilityScope
264
+ )
274
265
275
- if self . options. enableExperimentalTestOutput, !runner. ranSuccessfully {
276
- try Self . handleTestOutput ( buildParameters: buildParameters, packagePath: testProducts [ 0 ] . packagePath)
277
- }
266
+ let testResults = try runner. run ( tests)
267
+
268
+ try generateXUnitOutputIfRequested ( for: testResults, swiftTool: swiftTool)
269
+
270
+ // process code Coverage if request
271
+ if self . options. enableCodeCoverage, runner. ranSuccessfully {
272
+ try processCodeCoverage ( testProducts, swiftTool: swiftTool, library: . xctest)
273
+ }
274
+
275
+ if !runner. ranSuccessfully {
276
+ swiftTool. executionStatus = . failure
278
277
}
279
278
280
- // Generate xUnit file if requested
281
- if let xUnitOutput = options. xUnitOutput {
282
- let generator = XUnitGenerator (
283
- fileSystem: swiftTool. fileSystem,
284
- results: testResults
285
- )
286
- try generator. generate ( at: xUnitOutput)
279
+ if self . options. enableExperimentalTestOutput, !runner. ranSuccessfully {
280
+ try Self . handleTestOutput ( buildParameters: buildParameters, packagePath: testProducts [ 0 ] . packagePath)
287
281
}
288
282
}
289
283
}
@@ -325,6 +319,19 @@ public struct SwiftTestTool: SwiftCommand {
325
319
}
326
320
}
327
321
322
+ /// Generate xUnit file if requested.
323
+ private func generateXUnitOutputIfRequested( for testResults: [ ParallelTestRunner . TestResult ] , swiftTool: SwiftTool ) throws {
324
+ guard let xUnitOutput = options. xUnitOutput else {
325
+ return
326
+ }
327
+
328
+ let generator = XUnitGenerator (
329
+ fileSystem: swiftTool. fileSystem,
330
+ results: testResults
331
+ )
332
+ try generator. generate ( at: xUnitOutput)
333
+ }
334
+
328
335
// MARK: - swift-testing
329
336
330
337
private func swiftTestingRun( _ swiftTool: SwiftTool ) throws {
0 commit comments