@@ -204,7 +204,7 @@ public struct SwiftTestTool: SwiftCommand {
204
204
205
205
public func run( _ swiftTool: SwiftTool ) throws {
206
206
// Validate commands arguments
207
- try validateArguments ( diagnostics : swiftTool. observabilityScope. makeDiagnosticsEngine ( ) )
207
+ try self . validateArguments ( observabilityScope : swiftTool. observabilityScope)
208
208
209
209
switch options. mode {
210
210
case . listTests:
@@ -301,7 +301,7 @@ public struct SwiftTestTool: SwiftCommand {
301
301
toolchain: toolchain,
302
302
testEnv: testEnv,
303
303
outputStream: swiftTool. outputStream,
304
- diagnostics : swiftTool. observabilityScope. makeDiagnosticsEngine ( )
304
+ observabilityScope : swiftTool. observabilityScope
305
305
)
306
306
307
307
// Finally, run the tests.
@@ -342,10 +342,10 @@ public struct SwiftTestTool: SwiftCommand {
342
342
toolchain: toolchain,
343
343
xUnitOutput: options. xUnitOutput,
344
344
numJobs: options. numberOfWorkers ?? ProcessInfo . processInfo. activeProcessorCount,
345
- diagnostics: swiftTool. observabilityScope. makeDiagnosticsEngine ( ) ,
346
345
options: swiftOptions,
347
346
buildParameters: buildParameters,
348
- outputStream: swiftTool. outputStream
347
+ outputStream: swiftTool. outputStream,
348
+ observabilityScope: swiftTool. observabilityScope
349
349
)
350
350
try runner. run ( tests, outputStream: swiftTool. outputStream)
351
351
@@ -527,24 +527,24 @@ public struct SwiftTestTool: SwiftCommand {
527
527
/// Private function that validates the commands arguments
528
528
///
529
529
/// - Throws: if a command argument is invalid
530
- private func validateArguments( diagnostics : DiagnosticsEngine ) throws {
530
+ private func validateArguments( observabilityScope : ObservabilityScope ) throws {
531
531
// Validation for --num-workers.
532
532
if let workers = options. numberOfWorkers {
533
533
534
534
// The --num-worker option should be called with --parallel.
535
535
guard options. mode == . runParallel else {
536
- diagnostics . emit ( error: " --num-workers must be used with --parallel " )
536
+ observabilityScope . emit ( error: " --num-workers must be used with --parallel " )
537
537
throw ExitCode . failure
538
538
}
539
539
540
540
guard workers > 0 else {
541
- diagnostics . emit ( error: " '--num-workers' must be greater than zero " )
541
+ observabilityScope . emit ( error: " '--num-workers' must be greater than zero " )
542
542
throw ExitCode . failure
543
543
}
544
544
}
545
545
546
546
if options. shouldGenerateLinuxMain {
547
- diagnostics . emit ( warning: " '--generate-linuxmain' option is deprecated; tests are automatically discovered on all platforms " )
547
+ observabilityScope . emit ( warning: " '--generate-linuxmain' option is deprecated; tests are automatically discovered on all platforms " )
548
548
}
549
549
}
550
550
@@ -589,8 +589,8 @@ final class TestRunner {
589
589
/// Output stream for test results
590
590
private let outputStream : OutputByteStream
591
591
592
- /// Diagnostics Engine to emit diagnostics.
593
- private let diagnostics : DiagnosticsEngine
592
+ /// ObservabilityScope to emit diagnostics.
593
+ private let observabilityScope : ObservabilityScope
594
594
595
595
/// Creates an instance of TestRunner.
596
596
///
@@ -604,15 +604,15 @@ final class TestRunner {
604
604
toolchain: UserToolchain ,
605
605
testEnv: [ String : String ] ,
606
606
outputStream: OutputByteStream ,
607
- diagnostics : DiagnosticsEngine
607
+ observabilityScope : ObservabilityScope
608
608
) {
609
609
self . bundlePaths = bundlePaths
610
610
self . xctestArg = xctestArg
611
611
self . processSet = processSet
612
612
self . toolchain = toolchain
613
613
self . testEnv = testEnv
614
614
self . outputStream = outputStream
615
- self . diagnostics = diagnostics
615
+ self . observabilityScope = observabilityScope . makeChildScope ( description : " Test Runner " )
616
616
}
617
617
618
618
/// Executes and returns execution status. Prints test output on standard streams if requested
@@ -657,6 +657,8 @@ final class TestRunner {
657
657
return String ( bytes: stdout + stderr, encoding: . utf8) ? . spm_chuzzle ( ) ?? " "
658
658
}
659
659
660
+ let testObservabilityScope = self . observabilityScope. makeChildScope ( description: " running test at \( path) " )
661
+
660
662
do {
661
663
let outputRedirection = Process . OutputRedirection. stream (
662
664
stdout: {
@@ -688,7 +690,7 @@ final class TestRunner {
688
690
default : break
689
691
}
690
692
} catch {
691
- self . diagnostics . emit ( error)
693
+ testObservabilityScope . emit ( error)
692
694
}
693
695
return ( false , makeOutput ( ) )
694
696
}
@@ -738,27 +740,27 @@ final class ParallelTestRunner {
738
740
/// Output stream for test results
739
741
private let outputStream : OutputByteStream
740
742
741
- /// Diagnostics Engine to emit diagnostics.
742
- private let diagnostics : DiagnosticsEngine
743
+ /// ObservabilityScope to emit diagnostics.
744
+ private let observabilityScope : ObservabilityScope
743
745
744
746
init (
745
747
bundlePaths: [ AbsolutePath ] ,
746
748
processSet: ProcessSet ,
747
749
toolchain: UserToolchain ,
748
750
xUnitOutput: AbsolutePath ? = nil ,
749
751
numJobs: Int ,
750
- diagnostics: DiagnosticsEngine ,
751
752
options: SwiftToolOptions ,
752
753
buildParameters: BuildParameters ,
753
- outputStream: OutputByteStream
754
+ outputStream: OutputByteStream ,
755
+ observabilityScope: ObservabilityScope
754
756
) {
755
757
self . bundlePaths = bundlePaths
756
758
self . processSet = processSet
757
759
self . toolchain = toolchain
758
760
self . xUnitOutput = xUnitOutput
759
761
self . numJobs = numJobs
760
762
self . outputStream = outputStream
761
- self . diagnostics = diagnostics
763
+ self . observabilityScope = observabilityScope . makeChildScope ( description : " Parallel Test Runner " )
762
764
763
765
if ProcessEnv . vars [ " SWIFTPM_TEST_RUNNER_PROGRESS_BAR " ] == " lit " {
764
766
progressAnimation = PercentProgressAnimation ( stream: outputStream, header: " Testing: " )
@@ -819,7 +821,7 @@ final class ParallelTestRunner {
819
821
toolchain: self . toolchain,
820
822
testEnv: testEnv,
821
823
outputStream: self . outputStream,
822
- diagnostics : self . diagnostics
824
+ observabilityScope : self . observabilityScope
823
825
)
824
826
let ( success, output) = testRunner. test ( writeToOutputStream: false )
825
827
if !success {
0 commit comments