@@ -185,7 +185,7 @@ public enum TestOutput: String, ExpressibleByArgument {
185
185
}
186
186
187
187
/// swift-test tool namespace
188
- public struct SwiftTestTool : SwiftCommand {
188
+ public struct SwiftTestTool : AsyncSwiftCommand {
189
189
public static var configuration = CommandConfiguration (
190
190
commandName: " test " ,
191
191
_superCommandName: " swift " ,
@@ -206,7 +206,7 @@ public struct SwiftTestTool: SwiftCommand {
206
206
207
207
// MARK: - XCTest
208
208
209
- private func xctestRun( _ swiftTool: SwiftTool ) throws {
209
+ private func xctestRun( _ swiftTool: SwiftTool ) async throws {
210
210
// validate XCTest available on darwin based systems
211
211
let toolchain = try swiftTool. getTargetToolchain ( )
212
212
let isHostTestingAvailable = try swiftTool. getHostToolchain ( ) . swiftSDK. supportsTesting
@@ -224,7 +224,13 @@ public struct SwiftTestTool: SwiftCommand {
224
224
let testProducts = try buildTestsIfNeeded ( swiftTool: swiftTool, library: . xctest)
225
225
if !self . options. shouldRunInParallel {
226
226
let xctestArgs = try xctestArgs ( for: testProducts, swiftTool: swiftTool)
227
- try runTestProducts ( testProducts, additionalArguments: xctestArgs, buildParameters: buildParameters, swiftTool: swiftTool, library: . xctest)
227
+ try await runTestProducts (
228
+ testProducts,
229
+ additionalArguments: xctestArgs,
230
+ buildParameters: buildParameters,
231
+ swiftTool: swiftTool,
232
+ library: . xctest
233
+ )
228
234
} else {
229
235
let testSuites = try TestingSupport . getTestSuites (
230
236
in: testProducts,
@@ -269,7 +275,7 @@ public struct SwiftTestTool: SwiftCommand {
269
275
270
276
// process code Coverage if request
271
277
if self . options. enableCodeCoverage, runner. ranSuccessfully {
272
- try processCodeCoverage ( testProducts, swiftTool: swiftTool, library: . xctest)
278
+ try await processCodeCoverage ( testProducts, swiftTool: swiftTool, library: . xctest)
273
279
}
274
280
275
281
if !runner. ranSuccessfully {
@@ -334,16 +340,22 @@ public struct SwiftTestTool: SwiftCommand {
334
340
335
341
// MARK: - swift-testing
336
342
337
- private func swiftTestingRun( _ swiftTool: SwiftTool ) throws {
343
+ private func swiftTestingRun( _ swiftTool: SwiftTool ) async throws {
338
344
let buildParameters = try swiftTool. buildParametersForTest ( options: self . options, library: . swiftTesting)
339
345
let testProducts = try buildTestsIfNeeded ( swiftTool: swiftTool, library: . swiftTesting)
340
346
let additionalArguments = Array ( CommandLine . arguments. dropFirst ( ) )
341
- try runTestProducts ( testProducts, additionalArguments: additionalArguments, buildParameters: buildParameters, swiftTool: swiftTool, library: . swiftTesting)
347
+ try await runTestProducts (
348
+ testProducts,
349
+ additionalArguments: additionalArguments,
350
+ buildParameters: buildParameters,
351
+ swiftTool: swiftTool,
352
+ library: . swiftTesting
353
+ )
342
354
}
343
355
344
356
// MARK: - Common implementation
345
357
346
- public func run( _ swiftTool: SwiftTool ) throws {
358
+ public func run( _ swiftTool: SwiftTool ) async throws {
347
359
do {
348
360
// Validate commands arguments
349
361
try self . validateArguments ( observabilityScope: swiftTool. observabilityScope)
@@ -353,22 +365,28 @@ public struct SwiftTestTool: SwiftCommand {
353
365
}
354
366
355
367
if self . options. shouldPrintCodeCovPath {
356
- try printCodeCovPath ( swiftTool)
368
+ try await printCodeCovPath ( swiftTool)
357
369
} else if self . options. _deprecated_shouldListTests {
358
370
// backward compatibility 6/2022 for deprecation of flag into a subcommand
359
371
let command = try List . parse ( )
360
372
try command. run ( swiftTool)
361
373
} else {
362
374
if options. sharedOptions. enableSwiftTestingLibrarySupport {
363
- try swiftTestingRun ( swiftTool)
375
+ try await swiftTestingRun ( swiftTool)
364
376
}
365
377
if options. sharedOptions. enableXCTestSupport {
366
- try xctestRun ( swiftTool)
378
+ try await xctestRun ( swiftTool)
367
379
}
368
380
}
369
381
}
370
382
371
- private func runTestProducts( _ testProducts: [ BuiltTestProduct ] , additionalArguments: [ String ] , buildParameters: BuildParameters , swiftTool: SwiftTool , library: BuildParameters . Testing . Library ) throws {
383
+ private func runTestProducts(
384
+ _ testProducts: [ BuiltTestProduct ] ,
385
+ additionalArguments: [ String ] ,
386
+ buildParameters: BuildParameters ,
387
+ swiftTool: SwiftTool ,
388
+ library: BuildParameters . Testing . Library
389
+ ) async throws {
372
390
// Clean out the code coverage directory that may contain stale
373
391
// profraw files from a previous run of the code coverage tool.
374
392
if self . options. enableCodeCoverage {
@@ -403,7 +421,7 @@ public struct SwiftTestTool: SwiftCommand {
403
421
}
404
422
405
423
if self . options. enableCodeCoverage, ranSuccessfully {
406
- try processCodeCoverage ( testProducts, swiftTool: swiftTool, library: library)
424
+ try await processCodeCoverage ( testProducts, swiftTool: swiftTool, library: library)
407
425
}
408
426
409
427
if self . options. enableExperimentalTestOutput, !ranSuccessfully {
@@ -443,16 +461,18 @@ public struct SwiftTestTool: SwiftCommand {
443
461
}
444
462
445
463
/// Processes the code coverage data and emits a json.
446
- private func processCodeCoverage( _ testProducts: [ BuiltTestProduct ] , swiftTool: SwiftTool , library: BuildParameters . Testing . Library ) throws {
464
+ private func processCodeCoverage(
465
+ _ testProducts: [ BuiltTestProduct ] ,
466
+ swiftTool: SwiftTool ,
467
+ library: BuildParameters . Testing . Library
468
+ ) async throws {
447
469
let workspace = try swiftTool. getActiveWorkspace ( )
448
470
let root = try swiftTool. getWorkspaceRoot ( )
449
- let rootManifests = try temp_await {
450
- workspace. loadRootManifests (
451
- packages: root. packages,
452
- observabilityScope: swiftTool. observabilityScope,
453
- completion: $0
454
- )
455
- }
471
+ let rootManifests = try await workspace. loadRootManifests (
472
+ packages: root. packages,
473
+ observabilityScope: swiftTool. observabilityScope
474
+ )
475
+
456
476
guard let rootManifest = rootManifests. values. first else {
457
477
throw StringError ( " invalid manifests at \( root. packages) " )
458
478
}
@@ -548,16 +568,14 @@ public struct SwiftTestTool: SwiftCommand {
548
568
}
549
569
550
570
extension SwiftTestTool {
551
- func printCodeCovPath( _ swiftTool: SwiftTool ) throws {
571
+ func printCodeCovPath( _ swiftTool: SwiftTool ) async throws {
552
572
let workspace = try swiftTool. getActiveWorkspace ( )
553
573
let root = try swiftTool. getWorkspaceRoot ( )
554
- let rootManifests = try temp_await {
555
- workspace. loadRootManifests (
556
- packages: root. packages,
557
- observabilityScope: swiftTool. observabilityScope,
558
- completion: $0
559
- )
560
- }
574
+ let rootManifests = try await workspace. loadRootManifests (
575
+ packages: root. packages,
576
+ observabilityScope: swiftTool. observabilityScope
577
+ )
578
+
561
579
guard let rootManifest = rootManifests. values. first else {
562
580
throw StringError ( " invalid manifests at \( root. packages) " )
563
581
}
0 commit comments