@@ -213,7 +213,13 @@ public class SwiftTestTool: SwiftTool<TestToolOptions> {
213
213
switch options. testCaseSpecifier {
214
214
case . none:
215
215
let runner = TestRunner (
216
- path: testPath, xctestArg: nil , processSet: processSet, sanitizers: options. sanitizers, toolchain: toolchain)
216
+ path: testPath,
217
+ xctestArg: nil ,
218
+ processSet: processSet,
219
+ sanitizers: options. sanitizers,
220
+ toolchain: toolchain,
221
+ diagnostics: diagnostics
222
+ )
217
223
ranSuccessfully = runner. test ( )
218
224
219
225
case . regex, . specific:
@@ -234,8 +240,13 @@ public class SwiftTestTool: SwiftTool<TestToolOptions> {
234
240
// Finally, run the tests.
235
241
for test in tests {
236
242
let runner = TestRunner (
237
- path: testPath, xctestArg: test. specifier,
238
- processSet: processSet, sanitizers: options. sanitizers, toolchain: toolchain)
243
+ path: testPath,
244
+ xctestArg: test. specifier,
245
+ processSet: processSet,
246
+ sanitizers: options. sanitizers,
247
+ toolchain: toolchain,
248
+ diagnostics: diagnostics
249
+ )
239
250
ranSuccessfully = runner. test ( ) && ranSuccessfully
240
251
}
241
252
}
@@ -264,7 +275,8 @@ public class SwiftTestTool: SwiftTool<TestToolOptions> {
264
275
sanitizers: options. sanitizers,
265
276
toolchain: toolchain,
266
277
xUnitOutput: options. xUnitOutput,
267
- numJobs: options. numberOfWorkers ?? ProcessInfo . processInfo. activeProcessorCount
278
+ numJobs: options. numberOfWorkers ?? ProcessInfo . processInfo. activeProcessorCount,
279
+ diagnostics: diagnostics
268
280
)
269
281
try runner. run ( tests)
270
282
@@ -446,18 +458,28 @@ final class TestRunner {
446
458
447
459
// The toolchain to use.
448
460
private let toolchain : UserToolchain
461
+
462
+ /// Diagnostics Engine to emit diagnostics.
463
+ let diagnostics : DiagnosticsEngine
449
464
450
465
/// Creates an instance of TestRunner.
451
466
///
452
467
/// - Parameters:
453
468
/// - path: Path to valid XCTest binary.
454
469
/// - xctestArg: Arguments to pass to XCTest.
455
- init ( path: AbsolutePath , xctestArg: String ? = nil , processSet: ProcessSet , sanitizers: EnabledSanitizers , toolchain: UserToolchain ) {
470
+ init ( path: AbsolutePath ,
471
+ xctestArg: String ? = nil ,
472
+ processSet: ProcessSet ,
473
+ sanitizers: EnabledSanitizers ,
474
+ toolchain: UserToolchain ,
475
+ diagnostics: DiagnosticsEngine
476
+ ) {
456
477
self . path = path
457
478
self . xctestArg = xctestArg
458
479
self . processSet = processSet
459
480
self . sanitizers = sanitizers
460
481
self . toolchain = toolchain
482
+ self . diagnostics = diagnostics
461
483
}
462
484
463
485
/// Constructs arguments to execute XCTest.
@@ -503,7 +525,9 @@ final class TestRunner {
503
525
output += " \n " + exitSignalText( code: signal)
504
526
default : break
505
527
}
506
- } catch { }
528
+ } catch {
529
+ diagnostics. emit ( error)
530
+ }
507
531
return ( success, output)
508
532
}
509
533
@@ -523,9 +547,7 @@ final class TestRunner {
523
547
default : break
524
548
}
525
549
} catch {
526
- // FIXME: We may need a better way to print errors from here.
527
- stderrStream <<< " error: \( error) " <<< " \n "
528
- stderrStream. flush ( )
550
+ diagnostics. emit ( error)
529
551
}
530
552
return false
531
553
}
@@ -572,23 +594,28 @@ final class ParallelTestRunner {
572
594
let toolchain : UserToolchain
573
595
let xUnitOutput : AbsolutePath ?
574
596
575
- /// Number of tests to execute in parallel
597
+ /// Number of tests to execute in parallel.
576
598
let numJobs : Int
577
599
600
+ /// Diagnostics Engine to emit diagnostics.
601
+ let diagnostics : DiagnosticsEngine
602
+
578
603
init (
579
604
testPath: AbsolutePath ,
580
605
processSet: ProcessSet ,
581
606
sanitizers: EnabledSanitizers ,
582
607
toolchain: UserToolchain ,
583
608
xUnitOutput: AbsolutePath ? = nil ,
584
- numJobs: Int
609
+ numJobs: Int ,
610
+ diagnostics: DiagnosticsEngine
585
611
) {
586
612
self . testPath = testPath
587
613
self . processSet = processSet
588
614
self . sanitizers = sanitizers
589
615
self . toolchain = toolchain
590
616
self . xUnitOutput = xUnitOutput
591
617
self . numJobs = numJobs
618
+ self . diagnostics = diagnostics
592
619
progressBar = createProgressBar ( forStream: stdoutStream, header: " Testing: " )
593
620
594
621
assert ( numJobs > 0 , " num jobs should be > 0 " )
@@ -635,7 +662,13 @@ final class ParallelTestRunner {
635
662
// Dequeue a specifier and run it till we encounter nil.
636
663
while let test = self . pendingTests. dequeue ( ) {
637
664
let testRunner = TestRunner (
638
- path: self . testPath, xctestArg: test. specifier, processSet: self . processSet, sanitizers: self . sanitizers, toolchain: self . toolchain)
665
+ path: self . testPath,
666
+ xctestArg: test. specifier,
667
+ processSet: self . processSet,
668
+ sanitizers: self . sanitizers,
669
+ toolchain: self . toolchain,
670
+ diagnostics: self . diagnostics
671
+ )
639
672
let ( success, output) = testRunner. test ( )
640
673
if !success {
641
674
self . ranSuccessfully = false
0 commit comments