@@ -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 */
@@ -599,13 +613,13 @@ export class TestRunner {
599
613
600
614
await TemporaryFolder . withNamedTemporaryFile ( fifoPipePath , async ( ) => {
601
615
if ( this . testArgs . hasSwiftTestingTests ) {
602
- const swiftTestBuildConfig =
603
- await LaunchConfigurations . createLaunchConfigurationForSwiftTesting (
604
- this . testArgs . swiftTestArgs ,
605
- this . folderContext ,
606
- fifoPipePath ,
607
- false
608
- ) ;
616
+ const swiftTestBuildConfig = DebugConfigurationFactory . swiftTestingConfig (
617
+ this . folderContext ,
618
+ fifoPipePath ,
619
+ TestKind . standard ,
620
+ this . testArgs . swiftTestArgs ,
621
+ true
622
+ ) ;
609
623
610
624
if ( swiftTestBuildConfig !== null ) {
611
625
// given we have already run a build task there is no need to have a pre launch task
@@ -644,14 +658,12 @@ export class TestRunner {
644
658
645
659
// create launch config for testing
646
660
if ( this . testArgs . hasXCTests ) {
647
- const xcTestBuildConfig =
648
- await LaunchConfigurations . createLaunchConfigurationForXCTestTesting (
649
- this . testArgs . xcTestArgs ,
650
- this . workspaceContext ,
651
- this . folderContext ,
652
- true ,
653
- false
654
- ) ;
661
+ const xcTestBuildConfig = DebugConfigurationFactory . xcTestConfig (
662
+ this . folderContext ,
663
+ TestKind . standard ,
664
+ this . testArgs . xcTestArgs ,
665
+ true
666
+ ) ;
655
667
656
668
if ( xcTestBuildConfig !== null ) {
657
669
// given we have already run a build task there is no need to have a pre launch task
@@ -766,111 +778,6 @@ export class TestRunner {
766
778
}
767
779
}
768
780
769
- class LaunchConfigurations {
770
- /**
771
- * Edit launch configuration to run tests
772
- * @param debugging Do we need this configuration for debugging
773
- * @param outputFile Debug output file
774
- * @returns
775
- */
776
- static createLaunchConfigurationForXCTestTesting (
777
- args : string [ ] ,
778
- workspaceContext : WorkspaceContext ,
779
- folderContext : FolderContext ,
780
- debugging : boolean ,
781
- coverage : boolean
782
- ) : vscode . DebugConfiguration | null {
783
- const testList = args . join ( "," ) ;
784
-
785
- if ( process . platform === "darwin" ) {
786
- // if debugging on macOS with Swift 5.6 we need to create a custom launch
787
- // configuration so we can set the system architecture
788
- const swiftVersion = workspaceContext . toolchain . swiftVersion ;
789
- if (
790
- debugging &&
791
- swiftVersion . isLessThan ( new Version ( 5 , 7 , 0 ) ) &&
792
- swiftVersion . isGreaterThanOrEqual ( new Version ( 5 , 6 , 0 ) )
793
- ) {
794
- let testFilterArg : string ;
795
- if ( testList . length > 0 ) {
796
- testFilterArg = `-XCTest ${ testList } ` ;
797
- } else {
798
- testFilterArg = "" ;
799
- }
800
- const testBuildConfig = createDarwinTestConfiguration ( folderContext , testFilterArg ) ;
801
- if ( testBuildConfig === null ) {
802
- return null ;
803
- }
804
- return testBuildConfig ;
805
- } else {
806
- const testBuildConfig = createXCTestConfiguration ( folderContext , true ) ;
807
- if ( testBuildConfig === null ) {
808
- return null ;
809
- }
810
-
811
- let additionalArgs : string [ ] = [ ] ;
812
- if ( testList . length > 0 ) {
813
- additionalArgs = args . flatMap ( arg => [ "--filter" , regexEscapedString ( arg ) ] ) ;
814
- }
815
-
816
- if ( coverage ) {
817
- additionalArgs = [ ...additionalArgs , "--enable-code-coverage" ] ;
818
- }
819
-
820
- testBuildConfig . args = [ ...testBuildConfig . args , ...additionalArgs ] ;
821
- testBuildConfig . terminal = "console" ;
822
-
823
- return testBuildConfig ;
824
- }
825
- } else {
826
- const testBuildConfig = createXCTestConfiguration ( folderContext , true ) ;
827
- if ( testBuildConfig === null ) {
828
- return null ;
829
- }
830
-
831
- let testFilterArg : string [ ] = [ ] ;
832
- if ( testList . length > 0 ) {
833
- testFilterArg = args . flatMap ( arg => [ "--filter" , regexEscapedString ( arg ) ] ) ;
834
- }
835
- if ( coverage ) {
836
- testFilterArg = [ ...testFilterArg , "--enable-code-coverage" ] ;
837
- }
838
- testBuildConfig . args = [ ...testBuildConfig . args , ...testFilterArg ] ;
839
-
840
- // output test logging to debug console so we can catch it with a tracker
841
- testBuildConfig . terminal = "console" ;
842
- return testBuildConfig ;
843
- }
844
- }
845
-
846
- static async createLaunchConfigurationForSwiftTesting (
847
- args : string [ ] ,
848
- folderContext : FolderContext ,
849
- fifoPipePath : string ,
850
- coverage : boolean
851
- ) : Promise < vscode . DebugConfiguration | null > {
852
- const testList = args . join ( "," ) ;
853
-
854
- const testBuildConfig = createSwiftTestConfiguration ( folderContext , fifoPipePath , true ) ;
855
- if ( testBuildConfig === null ) {
856
- return null ;
857
- }
858
-
859
- let additionalArgs : string [ ] = [ ] ;
860
- if ( testList . length > 0 ) {
861
- additionalArgs = args . flatMap ( arg => [ "--filter" , regexEscapedString ( arg ) ] ) ;
862
- }
863
-
864
- if ( coverage ) {
865
- additionalArgs = [ ...additionalArgs , "--enable-code-coverage" ] ;
866
- }
867
-
868
- testBuildConfig . args = [ ...testBuildConfig . args , ...additionalArgs ] ;
869
- testBuildConfig . terminal = "console" ;
870
- return testBuildConfig ;
871
- }
872
- }
873
-
874
781
/** Interface defining how to find test items given a test id from XCTest output */
875
782
interface TestItemFinder {
876
783
getIndex ( id : string , filename ?: string ) : number ;
0 commit comments