@@ -19,12 +19,11 @@ import * as os from "os";
19
19
import * as asyncfs from "fs/promises" ;
20
20
import { FolderContext } from "../FolderContext" ;
21
21
import { execFile , getErrorDescription } from "../utilities/utilities" ;
22
- import { getBuildAllTask } from "../tasks/SwiftTaskProvider" ;
22
+ import { createSwiftTask } from "../tasks/SwiftTaskProvider" ;
23
23
import configuration from "../configuration" ;
24
24
import { WorkspaceContext } from "../WorkspaceContext" ;
25
25
import { XCTestOutputParser } from "./TestParsers/XCTestOutputParser" ;
26
26
import { SwiftTestingOutputParser } from "./TestParsers/SwiftTestingOutputParser" ;
27
- import { Version } from "../utilities/version" ;
28
27
import { LoggingDebugAdapterTracker } from "../debugger/logTracker" ;
29
28
import { TaskOperation } from "../tasks/TaskQueue" ;
30
29
import { TestXUnitParser , iXUnitTestState } from "./TestXUnitParser" ;
@@ -34,16 +33,15 @@ import { TemporaryFolder } from "../utilities/tempFolder";
34
33
import { TestClass , runnableTag , upsertTestItem } from "./TestDiscovery" ;
35
34
import { TestCoverage } from "../coverage/LcovResults" ;
36
35
import { DebugConfigurationFactory } from "../debugger/buildConfig" ;
37
- import { SwiftPtyProcess } from "../tasks/SwiftProcess" ;
38
36
39
37
/** Workspace Folder events */
40
38
export enum TestKind {
41
39
// run tests serially
42
- standard = "standard " ,
40
+ standard = "Standard " ,
43
41
// run tests in parallel
44
- parallel = "parallel " ,
42
+ parallel = "Parallel " ,
45
43
// run tests and extract test coverage
46
- coverage = "coverage " ,
44
+ coverage = "Coverage " ,
47
45
}
48
46
49
47
export enum TestLibrary {
@@ -309,28 +307,6 @@ export class TestRunner {
309
307
async runHandler ( shouldDebug : boolean , testKind : TestKind , token : vscode . CancellationToken ) {
310
308
const runState = new TestRunnerTestRunState ( this . testRun ) ;
311
309
try {
312
- // run associated build task
313
- // don't do this if generating code test coverage data as the
314
- // `swift test --enable-code-coverage` command will rebuild everything again.
315
- if ( testKind !== TestKind . coverage ) {
316
- const task = await getBuildAllTask ( this . folderContext ) ;
317
- task . definition . dontTriggerTestDiscovery =
318
- this . folderContext . workspaceContext . swiftVersion . isGreaterThanOrEqual (
319
- new Version ( 6 , 0 , 0 )
320
- ) ;
321
-
322
- const exitCode = await this . folderContext . taskQueue . queueOperation (
323
- new TaskOperation ( task ) ,
324
- token
325
- ) ;
326
-
327
- // if build failed then exit
328
- if ( exitCode === undefined || exitCode !== 0 ) {
329
- await this . testRun . end ( ) ;
330
- return ;
331
- }
332
- }
333
-
334
310
if ( shouldDebug ) {
335
311
await this . debugSession ( token , runState ) ;
336
312
} else {
@@ -449,7 +425,6 @@ export class TestRunner {
449
425
testBuildConfig : vscode . DebugConfiguration ,
450
426
testLibrary : TestLibrary
451
427
) {
452
- this . testRun . appendOutput ( `> Test run started at ${ new Date ( ) . toLocaleString ( ) } <\r\n\r\n` ) ;
453
428
try {
454
429
switch ( testKind ) {
455
430
case TestKind . coverage :
@@ -464,7 +439,7 @@ export class TestRunner {
464
439
await this . runParallelSession ( token , outputStream , testBuildConfig ) ;
465
440
break ;
466
441
default :
467
- await this . runStandardSession ( token , outputStream , testBuildConfig ) ;
442
+ await this . runStandardSession ( token , outputStream , testBuildConfig , testKind ) ;
468
443
break ;
469
444
}
470
445
} catch ( error ) {
@@ -481,35 +456,53 @@ export class TestRunner {
481
456
async runStandardSession (
482
457
token : vscode . CancellationToken ,
483
458
outputStream : stream . Writable ,
484
- testBuildConfig : vscode . DebugConfiguration
459
+ testBuildConfig : vscode . DebugConfiguration ,
460
+ testKind : TestKind
485
461
) {
486
462
return new Promise < void > ( ( resolve , reject ) => {
487
463
const args = testBuildConfig . args ?? [ ] ;
488
- let didError = false ;
489
- let cancellation : vscode . Disposable ;
464
+ this . folderContext ?. workspaceContext . outputChannel . logDiagnostic (
465
+ `Exec: ${ testBuildConfig . program } ${ args . join ( " " ) } ` ,
466
+ this . folderContext . name
467
+ ) ;
490
468
491
- const exec = new SwiftPtyProcess ( testBuildConfig . program , args , {
492
- cwd : testBuildConfig . cwd ,
493
- env : { ...process . env , ...testBuildConfig . env } ,
494
- } ) ;
469
+ let kindLabel : string ;
470
+ switch ( testKind ) {
471
+ case TestKind . coverage :
472
+ kindLabel = " With Code Coverage" ;
473
+ break ;
474
+ case TestKind . parallel :
475
+ kindLabel = " In Parallel" ;
476
+ break ;
477
+ case TestKind . standard :
478
+ kindLabel = "" ;
479
+ }
495
480
496
- exec . onDidWrite ( str => {
497
- // Work around SPM still emitting progress when doing --no-build.
498
- const replaced = str . replace ( "[1/1] Planning build" , "" ) ;
499
- outputStream . write ( replaced ) ;
500
- } ) ;
481
+ const task = createSwiftTask (
482
+ args ,
483
+ `Building and Running Tests${ kindLabel } ` ,
484
+ {
485
+ cwd : this . folderContext . folder ,
486
+ scope : this . folderContext . workspaceFolder ,
487
+ prefix : this . folderContext . name ,
488
+ presentationOptions : { reveal : vscode . TaskRevealKind . Silent } ,
489
+ } ,
490
+ this . folderContext . workspaceContext . toolchain ,
491
+ { ...process . env , ...testBuildConfig . env }
492
+ ) ;
501
493
502
- exec . onDidThrowError ( err => {
503
- didError = true ;
504
- reject ( err ) ;
494
+ task . execution . onDidWrite ( str => {
495
+ const replaced = str
496
+ . replace ( "[1/1] Planning build" , "" ) // Work around SPM still emitting progress when doing --no-build.
497
+ . replace (
498
+ / L L V M P r o f i l e E r r o r : F a i l e d t o w r i t e f i l e " d e f a u l t .p r o f r a w " : O p e r a t i o n n o t p e r m i t t e d \r \n / gm,
499
+ ""
500
+ ) ; // Work around benign LLVM coverage warnings
501
+ outputStream . write ( replaced ) ;
505
502
} ) ;
506
503
507
- exec . onDidClose ( code => {
508
- // onDidClose is still called after an error
509
- if ( didError ) {
510
- return ;
511
- }
512
-
504
+ let cancellation : vscode . Disposable ;
505
+ task . execution . onDidClose ( code => {
513
506
if ( cancellation ) {
514
507
cancellation . dispose ( ) ;
515
508
}
@@ -522,17 +515,7 @@ export class TestRunner {
522
515
}
523
516
} ) ;
524
517
525
- if ( token ) {
526
- cancellation = token . onCancellationRequested ( ( ) => {
527
- exec . kill ( ) ;
528
- } ) ;
529
- }
530
-
531
- this . folderContext ?. workspaceContext . outputChannel . logDiagnostic (
532
- `Exec: ${ testBuildConfig . program } ${ args . join ( " " ) } ` ,
533
- this . folderContext . name
534
- ) ;
535
- exec . spawn ( ) ;
518
+ this . folderContext . taskQueue . queueOperation ( new TaskOperation ( task ) , token ) ;
536
519
} ) ;
537
520
}
538
521
@@ -544,7 +527,7 @@ export class TestRunner {
544
527
testLibrary : TestLibrary
545
528
) {
546
529
try {
547
- await this . runStandardSession ( token , outputStream , testBuildConfig ) ;
530
+ await this . runStandardSession ( token , outputStream , testBuildConfig , TestKind . coverage ) ;
548
531
} catch ( error ) {
549
532
// If this isn't a standard test failure, forward the error and skip generating coverage.
550
533
if ( error !== 1 ) {
@@ -578,10 +561,15 @@ export class TestRunner {
578
561
this . testRun . testRunStarted ( ) ;
579
562
580
563
try {
581
- testBuildConfig . args = await this . runStandardSession ( token , outputStream , {
582
- ...testBuildConfig ,
583
- args : [ ...args , filterArgs ] ,
584
- } ) ;
564
+ testBuildConfig . args = await this . runStandardSession (
565
+ token ,
566
+ outputStream ,
567
+ {
568
+ ...testBuildConfig ,
569
+ args : [ ...args , filterArgs ] ,
570
+ } ,
571
+ TestKind . parallel
572
+ ) ;
585
573
} catch ( error ) {
586
574
// If this isn't a standard test failure, forward the error and skip generating coverage.
587
575
if ( error !== 1 ) {
@@ -727,11 +715,6 @@ export class TestRunner {
727
715
. then (
728
716
started => {
729
717
if ( started ) {
730
- if ( config === validBuildConfigs [ 0 ] ) {
731
- this . testRun . appendOutput (
732
- `> Test run started at ${ new Date ( ) . toLocaleString ( ) } <\r\n\r\n`
733
- ) ;
734
- }
735
718
// show test results pane
736
719
vscode . commands . executeCommand (
737
720
"testing.showMostRecentOutput"
0 commit comments