@@ -31,6 +31,7 @@ import { Sanitizer } from "./Sanitizer";
31
31
interface InfoPlist {
32
32
DefaultProperties : {
33
33
XCTEST_VERSION : string | undefined ;
34
+ SWIFT_TESTING_VERSION : string | undefined ;
34
35
} ;
35
36
}
36
37
@@ -107,6 +108,7 @@ export class SwiftToolchain {
107
108
public defaultSDK ?: string ,
108
109
public customSDK ?: string ,
109
110
public xcTestPath ?: string ,
111
+ public swiftTestingPath ?: string ,
110
112
public swiftPMTestingHelperPath ?: string
111
113
) { }
112
114
@@ -125,6 +127,12 @@ export class SwiftToolchain {
125
127
runtimePath ,
126
128
customSDK ?? defaultSDK
127
129
) ;
130
+ const swiftTestingPath = await this . getSwiftTestingPath (
131
+ targetInfo ,
132
+ swiftVersion ,
133
+ runtimePath ,
134
+ customSDK ?? defaultSDK
135
+ ) ;
128
136
const swiftPMTestingHelperPath = await this . getSwiftPMTestingHelperPath ( toolchainPath ) ;
129
137
130
138
return new SwiftToolchain (
@@ -137,6 +145,7 @@ export class SwiftToolchain {
137
145
defaultSDK ,
138
146
customSDK ,
139
147
xcTestPath ,
148
+ swiftTestingPath ,
140
149
swiftPMTestingHelperPath
141
150
) ;
142
151
}
@@ -638,6 +647,31 @@ export class SwiftToolchain {
638
647
return undefined ;
639
648
}
640
649
650
+ /**
651
+ * @param targetInfo swift target info
652
+ * @param swiftVersion parsed swift version
653
+ * @param runtimePath path to Swift runtime
654
+ * @param sdkroot path to swift SDK
655
+ * @returns path to folder where xctest can be found
656
+ */
657
+ private static async getSwiftTestingPath (
658
+ targetInfo : SwiftTargetInfo ,
659
+ swiftVersion : Version ,
660
+ runtimePath : string | undefined ,
661
+ sdkroot : string | undefined
662
+ ) : Promise < string | undefined > {
663
+ if ( process . platform !== "win32" ) {
664
+ return undefined ;
665
+ }
666
+ return this . getWindowsPlatformDLLPath (
667
+ "Testing" ,
668
+ targetInfo ,
669
+ swiftVersion ,
670
+ runtimePath ,
671
+ sdkroot
672
+ ) ;
673
+ }
674
+
641
675
/**
642
676
* @param targetInfo swift target info
643
677
* @param swiftVersion parsed swift version
@@ -663,80 +697,95 @@ export class SwiftToolchain {
663
697
return path . join ( developerDir , "usr" , "bin" ) ;
664
698
}
665
699
case "win32" : {
666
- // look up runtime library directory for XCTest alternatively
667
- const fallbackPath =
668
- runtimePath !== undefined &&
669
- ( await pathExists ( path . join ( runtimePath , "XCTest.dll" ) ) )
670
- ? runtimePath
671
- : undefined ;
672
- if ( ! sdkroot ) {
673
- return fallbackPath ;
674
- }
675
- const platformPath = path . dirname ( path . dirname ( path . dirname ( sdkroot ) ) ) ;
676
- const platformManifest = path . join ( platformPath , "Info.plist" ) ;
677
- if ( ( await pathExists ( platformManifest ) ) !== true ) {
678
- if ( fallbackPath ) {
679
- return fallbackPath ;
680
- }
681
- vscode . window . showWarningMessage (
682
- "XCTest not found due to non-standardized library layout. Tests explorer won't work as expected."
683
- ) ;
684
- return undefined ;
685
- }
686
- const data = await fs . readFile ( platformManifest , "utf8" ) ;
687
- let infoPlist ;
688
- try {
689
- infoPlist = plist . parse ( data ) as unknown as InfoPlist ;
690
- } catch ( error ) {
691
- vscode . window . showWarningMessage (
692
- `Unable to parse ${ platformManifest } : ${ error } `
693
- ) ;
694
- return undefined ;
695
- }
696
- const version = infoPlist . DefaultProperties . XCTEST_VERSION ;
697
- if ( ! version ) {
698
- throw Error ( "Info.plist is missing the XCTEST_VERSION key." ) ;
699
- }
700
-
701
- if ( swiftVersion . isGreaterThanOrEqual ( new Version ( 5 , 7 , 0 ) ) ) {
702
- let bindir : string ;
703
- const arch = targetInfo . target ?. triple . split ( "-" , 1 ) [ 0 ] ;
704
- switch ( arch ) {
705
- case "x86_64" :
706
- bindir = "bin64" ;
707
- break ;
708
- case "i686" :
709
- bindir = "bin32" ;
710
- break ;
711
- case "aarch64" :
712
- bindir = "bin64a" ;
713
- break ;
714
- default :
715
- throw Error ( `unsupported architecture ${ arch } ` ) ;
716
- }
717
- return path . join (
718
- platformPath ,
719
- "Developer" ,
720
- "Library" ,
721
- `XCTest-${ version } ` ,
722
- "usr" ,
723
- bindir
724
- ) ;
725
- } else {
726
- return path . join (
727
- platformPath ,
728
- "Developer" ,
729
- "Library" ,
730
- `XCTest-${ version } ` ,
731
- "usr" ,
732
- "bin"
733
- ) ;
734
- }
700
+ return await this . getWindowsPlatformDLLPath (
701
+ "XCTest" ,
702
+ targetInfo ,
703
+ swiftVersion ,
704
+ runtimePath ,
705
+ sdkroot
706
+ ) ;
735
707
}
736
708
}
737
709
return undefined ;
738
710
}
739
711
712
+ private static async getWindowsPlatformDLLPath (
713
+ type : "XCTest" | "Testing" ,
714
+ targetInfo : SwiftTargetInfo ,
715
+ swiftVersion : Version ,
716
+ runtimePath : string | undefined ,
717
+ sdkroot : string | undefined
718
+ ) : Promise < string | undefined > {
719
+ // look up runtime library directory for XCTest/Testing alternatively
720
+ const fallbackPath =
721
+ runtimePath !== undefined && ( await pathExists ( path . join ( runtimePath , `${ type } .dll` ) ) )
722
+ ? runtimePath
723
+ : undefined ;
724
+ if ( ! sdkroot ) {
725
+ return fallbackPath ;
726
+ }
727
+
728
+ const platformPath = path . dirname ( path . dirname ( path . dirname ( sdkroot ) ) ) ;
729
+ const platformManifest = path . join ( platformPath , "Info.plist" ) ;
730
+ if ( ( await pathExists ( platformManifest ) ) !== true ) {
731
+ if ( fallbackPath ) {
732
+ return fallbackPath ;
733
+ }
734
+ vscode . window . showWarningMessage (
735
+ `${ type } not found due to non-standardized library layout. Tests explorer won't work as expected.`
736
+ ) ;
737
+ return undefined ;
738
+ }
739
+ const data = await fs . readFile ( platformManifest , "utf8" ) ;
740
+ let infoPlist ;
741
+ try {
742
+ infoPlist = plist . parse ( data ) as unknown as InfoPlist ;
743
+ } catch ( error ) {
744
+ vscode . window . showWarningMessage ( `Unable to parse ${ platformManifest } : ${ error } ` ) ;
745
+ return undefined ;
746
+ }
747
+ const plistKey = type === "XCTest" ? "XCTEST_VERSION" : "SWIFT_TESTING_VERSION" ;
748
+ const version = infoPlist . DefaultProperties [ plistKey ] ;
749
+ if ( ! version ) {
750
+ throw Error ( `Info.plist is missing the ${ plistKey } key.` ) ;
751
+ }
752
+
753
+ if ( swiftVersion . isGreaterThanOrEqual ( new Version ( 5 , 7 , 0 ) ) ) {
754
+ let bindir : string ;
755
+ const arch = targetInfo . target ?. triple . split ( "-" , 1 ) [ 0 ] ;
756
+ switch ( arch ) {
757
+ case "x86_64" :
758
+ bindir = "bin64" ;
759
+ break ;
760
+ case "i686" :
761
+ bindir = "bin32" ;
762
+ break ;
763
+ case "aarch64" :
764
+ bindir = "bin64a" ;
765
+ break ;
766
+ default :
767
+ throw Error ( `unsupported architecture ${ arch } ` ) ;
768
+ }
769
+ return path . join (
770
+ platformPath ,
771
+ "Developer" ,
772
+ "Library" ,
773
+ `${ type } -${ version } ` ,
774
+ "usr" ,
775
+ bindir
776
+ ) ;
777
+ } else {
778
+ return path . join (
779
+ platformPath ,
780
+ "Developer" ,
781
+ "Library" ,
782
+ `${ type } -${ version } ` ,
783
+ "usr" ,
784
+ "bin"
785
+ ) ;
786
+ }
787
+ }
788
+
740
789
/** @returns swift target info */
741
790
private static async getSwiftTargetInfo ( ) : Promise < SwiftTargetInfo > {
742
791
try {
0 commit comments