@@ -17,14 +17,9 @@ import * as path from "path";
17
17
import * as stream from "stream" ;
18
18
import * as os from "os" ;
19
19
import * as asyncfs from "fs/promises" ;
20
- import {
21
- createXCTestConfiguration ,
22
- createSwiftTestConfiguration ,
23
- createDarwinTestConfiguration ,
24
- } from "../debugger/launch" ;
25
20
import { FolderContext } from "../FolderContext" ;
21
+ import { execFile , getErrorDescription } from "../utilities/utilities" ;
26
22
import { getBuildAllTask } from "../tasks/SwiftTaskProvider" ;
27
- import { execFile , getErrorDescription , regexEscapedString } from "../utilities/utilities" ;
28
23
import configuration from "../configuration" ;
29
24
import { WorkspaceContext } from "../WorkspaceContext" ;
30
25
import { XCTestOutputParser } from "./TestParsers/XCTestOutputParser" ;
@@ -37,8 +32,9 @@ import { ITestRunState } from "./TestParsers/TestRunState";
37
32
import { TestRunArguments } from "./TestRunArguments" ;
38
33
import { TemporaryFolder } from "../utilities/tempFolder" ;
39
34
import { TestClass , runnableTag , upsertTestItem } from "./TestDiscovery" ;
40
- import { SwiftProcess } from "../tasks/SwiftProcess" ;
41
- import { TestCoverage } from "../coverage/TestCoverage" ;
35
+ import { TestCoverage } from "../coverage/LcovResults" ;
36
+ import { DebugConfigurationFactory } from "../debugger/buildConfig" ;
37
+ import { SwiftPtyProcess } from "../tasks/SwiftProcess" ;
42
38
43
39
/** Workspace Folder events */
44
40
export enum TestKind {
@@ -50,6 +46,11 @@ export enum TestKind {
50
46
coverage = "coverage" ,
51
47
}
52
48
49
+ export enum TestLibrary {
50
+ xctest = "XCTest" ,
51
+ swiftTesting = "swift-testing" ,
52
+ }
53
+
53
54
class TestRunProxy {
54
55
private testRun ?: vscode . TestRun ;
55
56
private addedTestItems : { testClass : TestClass ; parentIndex : number } [ ] = [ ] ;
@@ -363,13 +364,13 @@ export class TestRunner {
363
364
await execFile ( "mkfifo" , [ fifoPipePath ] , undefined , this . folderContext ) ;
364
365
}
365
366
366
- const testBuildConfig =
367
- await LaunchConfigurations . createLaunchConfigurationForSwiftTesting (
368
- this . testArgs . swiftTestArgs ,
369
- this . folderContext ,
370
- fifoPipePath ,
371
- testKind === TestKind . coverage
372
- ) ;
367
+ const testBuildConfig = DebugConfigurationFactory . swiftTestingConfig (
368
+ this . folderContext ,
369
+ fifoPipePath ,
370
+ testKind ,
371
+ this . testArgs . swiftTestArgs ,
372
+ true
373
+ ) ;
373
374
374
375
if ( testBuildConfig === null ) {
375
376
return ;
@@ -397,18 +398,18 @@ export class TestRunner {
397
398
testKind === TestKind . parallel ? TestKind . standard : testKind ,
398
399
token ,
399
400
outputStream ,
400
- testBuildConfig
401
+ testBuildConfig ,
402
+ TestLibrary . swiftTesting
401
403
) ;
402
404
} ) ;
403
405
}
404
406
405
407
if ( this . testArgs . hasXCTests ) {
406
- const testBuildConfig = LaunchConfigurations . createLaunchConfigurationForXCTestTesting (
407
- this . testArgs . xcTestArgs ,
408
- this . workspaceContext ,
408
+ const testBuildConfig = DebugConfigurationFactory . xcTestConfig (
409
409
this . folderContext ,
410
- false ,
411
- testKind === TestKind . coverage
410
+ testKind ,
411
+ this . testArgs . xcTestArgs ,
412
+ true
412
413
) ;
413
414
if ( testBuildConfig === null ) {
414
415
return ;
@@ -431,21 +432,33 @@ export class TestRunner {
431
432
// XCTestRuns are started immediately
432
433
this . testRun . testRunStarted ( ) ;
433
434
434
- await this . launchTests ( testKind , token , parsedOutputStream , testBuildConfig ) ;
435
+ await this . launchTests (
436
+ testKind ,
437
+ token ,
438
+ parsedOutputStream ,
439
+ testBuildConfig ,
440
+ TestLibrary . xctest
441
+ ) ;
435
442
}
436
443
}
437
444
438
445
private async launchTests (
439
446
testKind : TestKind ,
440
447
token : vscode . CancellationToken ,
441
448
outputStream : stream . Writable ,
442
- testBuildConfig : vscode . DebugConfiguration
449
+ testBuildConfig : vscode . DebugConfiguration ,
450
+ testLibrary : TestLibrary
443
451
) {
444
452
this . testRun . appendOutput ( `> Test run started at ${ new Date ( ) . toLocaleString ( ) } <\r\n\r\n` ) ;
445
453
try {
446
454
switch ( testKind ) {
447
455
case TestKind . coverage :
448
- await this . runCoverageSession ( token , outputStream , testBuildConfig ) ;
456
+ await this . runCoverageSession (
457
+ token ,
458
+ outputStream ,
459
+ testBuildConfig ,
460
+ testLibrary
461
+ ) ;
449
462
break ;
450
463
case TestKind . parallel :
451
464
await this . runParallelSession ( token , outputStream , testBuildConfig ) ;
@@ -475,7 +488,7 @@ export class TestRunner {
475
488
let didError = false ;
476
489
let cancellation : vscode . Disposable ;
477
490
478
- const exec = new SwiftProcess ( testBuildConfig . program , args , {
491
+ const exec = new SwiftPtyProcess ( testBuildConfig . program , args , {
479
492
cwd : testBuildConfig . cwd ,
480
493
env : { ...process . env , ...testBuildConfig . env } ,
481
494
} ) ;
@@ -527,7 +540,8 @@ export class TestRunner {
527
540
async runCoverageSession (
528
541
token : vscode . CancellationToken ,
529
542
outputStream : stream . Writable ,
530
- testBuildConfig : vscode . DebugConfiguration
543
+ testBuildConfig : vscode . DebugConfiguration ,
544
+ testLibrary : TestLibrary
531
545
) {
532
546
try {
533
547
await this . runStandardSession ( token , outputStream , testBuildConfig ) ;
@@ -538,7 +552,7 @@ export class TestRunner {
538
552
}
539
553
}
540
554
541
- await this . testRun . coverage . captureCoverage ( ) ;
555
+ await this . testRun . coverage . captureCoverage ( testLibrary ) ;
542
556
}
543
557
544
558
/** Run tests in parallel outside of debugger */
@@ -605,13 +619,13 @@ export class TestRunner {
605
619
}
606
620
607
621
if ( this . testArgs . hasSwiftTestingTests ) {
608
- const swiftTestBuildConfig =
609
- await LaunchConfigurations . createLaunchConfigurationForSwiftTesting (
610
- this . testArgs . swiftTestArgs ,
611
- this . folderContext ,
612
- fifoPipePath ,
613
- false
614
- ) ;
622
+ const swiftTestBuildConfig = DebugConfigurationFactory . swiftTestingConfig (
623
+ this . folderContext ,
624
+ fifoPipePath ,
625
+ TestKind . standard ,
626
+ this . testArgs . swiftTestArgs ,
627
+ true
628
+ ) ;
615
629
616
630
if ( swiftTestBuildConfig !== null ) {
617
631
// given we have already run a build task there is no need to have a pre launch task
@@ -650,14 +664,12 @@ export class TestRunner {
650
664
651
665
// create launch config for testing
652
666
if ( this . testArgs . hasXCTests ) {
653
- const xcTestBuildConfig =
654
- await LaunchConfigurations . createLaunchConfigurationForXCTestTesting (
655
- this . testArgs . xcTestArgs ,
656
- this . workspaceContext ,
657
- this . folderContext ,
658
- true ,
659
- false
660
- ) ;
667
+ const xcTestBuildConfig = DebugConfigurationFactory . xcTestConfig (
668
+ this . folderContext ,
669
+ TestKind . standard ,
670
+ this . testArgs . xcTestArgs ,
671
+ true
672
+ ) ;
661
673
662
674
if ( xcTestBuildConfig !== null ) {
663
675
// given we have already run a build task there is no need to have a pre launch task
@@ -772,111 +784,6 @@ export class TestRunner {
772
784
}
773
785
}
774
786
775
- class LaunchConfigurations {
776
- /**
777
- * Edit launch configuration to run tests
778
- * @param debugging Do we need this configuration for debugging
779
- * @param outputFile Debug output file
780
- * @returns
781
- */
782
- static createLaunchConfigurationForXCTestTesting (
783
- args : string [ ] ,
784
- workspaceContext : WorkspaceContext ,
785
- folderContext : FolderContext ,
786
- debugging : boolean ,
787
- coverage : boolean
788
- ) : vscode . DebugConfiguration | null {
789
- const testList = args . join ( "," ) ;
790
-
791
- if ( process . platform === "darwin" ) {
792
- // if debugging on macOS with Swift 5.6 we need to create a custom launch
793
- // configuration so we can set the system architecture
794
- const swiftVersion = workspaceContext . toolchain . swiftVersion ;
795
- if (
796
- debugging &&
797
- swiftVersion . isLessThan ( new Version ( 5 , 7 , 0 ) ) &&
798
- swiftVersion . isGreaterThanOrEqual ( new Version ( 5 , 6 , 0 ) )
799
- ) {
800
- let testFilterArg : string ;
801
- if ( testList . length > 0 ) {
802
- testFilterArg = `-XCTest ${ testList } ` ;
803
- } else {
804
- testFilterArg = "" ;
805
- }
806
- const testBuildConfig = createDarwinTestConfiguration ( folderContext , testFilterArg ) ;
807
- if ( testBuildConfig === null ) {
808
- return null ;
809
- }
810
- return testBuildConfig ;
811
- } else {
812
- const testBuildConfig = createXCTestConfiguration ( folderContext , true ) ;
813
- if ( testBuildConfig === null ) {
814
- return null ;
815
- }
816
-
817
- let additionalArgs : string [ ] = [ ] ;
818
- if ( testList . length > 0 ) {
819
- additionalArgs = args . flatMap ( arg => [ "--filter" , regexEscapedString ( arg ) ] ) ;
820
- }
821
-
822
- if ( coverage ) {
823
- additionalArgs = [ ...additionalArgs , "--enable-code-coverage" ] ;
824
- }
825
-
826
- testBuildConfig . args = [ ...testBuildConfig . args , ...additionalArgs ] ;
827
- testBuildConfig . terminal = "console" ;
828
-
829
- return testBuildConfig ;
830
- }
831
- } else {
832
- const testBuildConfig = createXCTestConfiguration ( folderContext , true ) ;
833
- if ( testBuildConfig === null ) {
834
- return null ;
835
- }
836
-
837
- let testFilterArg : string [ ] = [ ] ;
838
- if ( testList . length > 0 ) {
839
- testFilterArg = args . flatMap ( arg => [ "--filter" , regexEscapedString ( arg ) ] ) ;
840
- }
841
- if ( coverage ) {
842
- testFilterArg = [ ...testFilterArg , "--enable-code-coverage" ] ;
843
- }
844
- testBuildConfig . args = [ ...testBuildConfig . args , ...testFilterArg ] ;
845
-
846
- // output test logging to debug console so we can catch it with a tracker
847
- testBuildConfig . terminal = "console" ;
848
- return testBuildConfig ;
849
- }
850
- }
851
-
852
- static async createLaunchConfigurationForSwiftTesting (
853
- args : string [ ] ,
854
- folderContext : FolderContext ,
855
- fifoPipePath : string ,
856
- coverage : boolean
857
- ) : Promise < vscode . DebugConfiguration | null > {
858
- const testList = args . join ( "," ) ;
859
-
860
- const testBuildConfig = createSwiftTestConfiguration ( folderContext , fifoPipePath , true ) ;
861
- if ( testBuildConfig === null ) {
862
- return null ;
863
- }
864
-
865
- let additionalArgs : string [ ] = [ ] ;
866
- if ( testList . length > 0 ) {
867
- additionalArgs = args . flatMap ( arg => [ "--filter" , regexEscapedString ( arg ) ] ) ;
868
- }
869
-
870
- if ( coverage ) {
871
- additionalArgs = [ ...additionalArgs , "--enable-code-coverage" ] ;
872
- }
873
-
874
- testBuildConfig . args = [ ...testBuildConfig . args , ...additionalArgs ] ;
875
- testBuildConfig . terminal = "console" ;
876
- return testBuildConfig ;
877
- }
878
- }
879
-
880
787
/** Interface defining how to find test items given a test id from XCTest output */
881
788
interface TestItemFinder {
882
789
getIndex ( id : string , filename ?: string ) : number ;
0 commit comments