@@ -14,6 +14,19 @@ import { isWindows } from '../../../../src/constants';
1414const assetsFolder = Uri . file ( path . normalize ( path . join ( __dirname . replace ( / d i s t [ \/ \\ ] / , '' ) , '..' , 'assets' ) ) ) ;
1515const assetsFolderFsPath = assetsFolder . fsPath ;
1616
17+ // A simple test counter for the tests that loop over several cases.
18+ // This is to make it easier to see which test failed in the output.
19+ // Start the counter with 1 instead of 0 since we're reporting on test cases, not arrays.
20+ class Counter {
21+ private count : number = 1 ;
22+ public next ( ) : void {
23+ this . count ++ ;
24+ }
25+ public get str ( ) : string {
26+ return `(test ${ this . count } )` ;
27+ }
28+ }
29+
1730if ( isWindows ) {
1831 describe ( 'extractCompilerPathAndArgs' , ( ) => {
1932 // [compilerPath, useLegacyBehavior, additionalArgs, result.compilerName, result.allCompilerArgs]
@@ -28,15 +41,19 @@ if (isWindows) {
2841 [ path . join ( 'bin' , 'gcc' ) , false , undefined , 'gcc' , [ ] ]
2942 ] ;
3043 it ( 'Verify various compilerPath strings without args' , ( ) => {
44+ const c = new Counter ( ) ;
3145 nonArgsTests . forEach ( test => {
3246 const result = extractCompilerPathAndArgs ( test [ 1 ] , test [ 0 ] , test [ 2 ] , assetsFolderFsPath ) ;
33- ok ( result . compilerPath ?. endsWith ( test [ 0 ] ) , `compilerPath should end with ${ test [ 0 ] } ` ) ;
34- equal ( result . compilerName , test [ 3 ] , 'compilerName should match' ) ;
35- deepEqual ( result . compilerArgs , test [ 2 ] , 'compilerArgs should match' ) ;
36- deepEqual ( result . compilerArgsFromCommandLineInPath , [ ] , 'compilerArgsFromCommandLineInPath should be empty' ) ;
37- deepEqual ( result . allCompilerArgs , test [ 4 ] , 'allCompilerArgs should match' ) ;
38- equal ( result . error , undefined , 'error should be undefined' ) ;
39- equal ( result . telemetry , undefined , 'telemetry should be undefined' ) ;
47+ ok ( result . compilerPath ?. endsWith ( test [ 0 ] ) , `${ c . str } compilerPath should end with ${ test [ 0 ] } ` ) ;
48+ equal ( result . compilerName , test [ 3 ] , `${ c . str } compilerName should match` ) ;
49+ deepEqual ( result . compilerArgs , test [ 2 ] , `${ c . str } compilerArgs should match` ) ;
50+ deepEqual ( result . compilerArgsFromCommandLineInPath , [ ] , `${ c . str } compilerArgsFromCommandLineInPath should be empty` ) ;
51+ deepEqual ( result . allCompilerArgs , test [ 4 ] , `${ c . str } allCompilerArgs should match` ) ;
52+
53+ // errors and telemetry are set by validateCompilerPath
54+ equal ( result . error , undefined , `${ c . str } error should be undefined` ) ;
55+ equal ( result . telemetry , undefined , `${ c . str } telemetry should be undefined` ) ;
56+ c . next ( ) ;
4057 } ) ;
4158 } ) ;
4259
@@ -53,31 +70,40 @@ if (isWindows) {
5370 [ `${ path . join ( 'bin' , 'gcc.exe' ) } -O2` , true , undefined , 'gcc.exe' , [ '-O2' ] ]
5471 ] ;
5572 it ( 'Verify various compilerPath strings with args' , ( ) => {
73+ const c = new Counter ( ) ;
5674 argsTests . forEach ( test => {
5775 const result = extractCompilerPathAndArgs ( test [ 1 ] , test [ 0 ] , test [ 2 ] ) ;
5876 const cp = test [ 0 ] . substring ( test [ 0 ] . at ( 0 ) === '"' ? 1 : 0 , test [ 0 ] . indexOf ( test [ 3 ] ) + test [ 3 ] . length ) ;
59- ok ( result . compilerPath ?. endsWith ( cp ) , `${ result . compilerPath } !endswith ${ cp } ` ) ;
60- equal ( result . compilerName , test [ 3 ] , 'compilerName should match' ) ;
61- deepEqual ( result . compilerArgs , test [ 2 ] , 'compilerArgs should match' ) ;
62- deepEqual ( result . compilerArgsFromCommandLineInPath , test [ 4 ] . filter ( a => ! test [ 2 ] ?. includes ( a ) ) , 'compilerArgsFromCommandLineInPath should match those from the command line' ) ;
63- deepEqual ( result . allCompilerArgs , test [ 4 ] , 'allCompilerArgs should match' ) ;
64- equal ( result . error , undefined , 'error should be undefined' ) ;
65- equal ( result . telemetry , undefined , 'telemetry should be undefined' ) ;
77+ ok ( result . compilerPath ?. endsWith ( cp ) , `${ c . str } ${ result . compilerPath } !endswith ${ cp } ` ) ;
78+ equal ( result . compilerName , test [ 3 ] , `${ c . str } compilerName should match` ) ;
79+ deepEqual ( result . compilerArgs , test [ 2 ] , `${ c . str } compilerArgs should match` ) ;
80+ deepEqual ( result . compilerArgsFromCommandLineInPath , test [ 4 ] . filter ( a => ! test [ 2 ] ?. includes ( a ) ) , `${ c . str } compilerArgsFromCommandLineInPath should match those from the command line` ) ;
81+ deepEqual ( result . allCompilerArgs , test [ 4 ] , `${ c . str } allCompilerArgs should match` ) ;
82+
83+ // errors and telemetry are set by validateCompilerPath
84+ equal ( result . error , undefined , `${ c . str } error should be undefined` ) ;
85+ equal ( result . telemetry , undefined , `${ c . str } telemetry should be undefined` ) ;
86+ c . next ( ) ;
6687 } ) ;
6788 } ) ;
6889
6990 const negativeTests : [ string , boolean , string [ ] | undefined , string , string [ ] ] [ ] = [
7091 [ `${ path . join ( assetsFolderFsPath , 'b i n' , 'clang++.exe' ) } -std=c++20` , false , undefined , 'b' , [ 'i' , 'n\\clang++.exe' , '-std=c++20' ] ]
7192 ] ;
7293 it ( 'Verify various compilerPath strings with args that should fail' , ( ) => {
94+ const c = new Counter ( ) ;
7395 negativeTests . forEach ( test => {
7496 const result = extractCompilerPathAndArgs ( test [ 1 ] , test [ 0 ] , test [ 2 ] ) ;
75- equal ( result . compilerName , test [ 3 ] , 'compilerName should match' ) ;
76- deepEqual ( result . allCompilerArgs , test [ 4 ] , 'allCompilerArgs should match' ) ;
97+ ok ( result . compilerPath ?. endsWith ( test [ 3 ] ) , `${ c . str } ${ result . compilerPath } !endswith ${ test [ 3 ] } ` ) ;
98+ equal ( result . compilerName , test [ 3 ] , `${ c . str } compilerName should match` ) ;
99+ deepEqual ( result . compilerArgs , test [ 2 ] , `${ c . str } compilerArgs should match` ) ;
100+ deepEqual ( result . compilerArgsFromCommandLineInPath , test [ 4 ] , `${ c . str } allCompilerArgs should match` ) ;
101+ deepEqual ( result . allCompilerArgs , test [ 4 ] , `${ c . str } allCompilerArgs should match` ) ;
77102
78103 // errors and telemetry are set by validateCompilerPath
79- equal ( result . error , undefined , 'error should be undefined' ) ;
80- equal ( result . telemetry , undefined , 'telemetry should be undefined' ) ;
104+ equal ( result . error , undefined , `${ c . str } error should be undefined` ) ;
105+ equal ( result . telemetry , undefined , `${ c . str } telemetry should be undefined` ) ;
106+ c . next ( ) ;
81107 } ) ;
82108 } ) ;
83109 } ) ;
@@ -91,12 +117,14 @@ if (isWindows) {
91117 [ path . join ( 'bin' , 'gcc' ) , false , undefined , 'gcc' , [ ] ]
92118 ] ;
93119 it ( 'Verify various compilerPath strings without args' , ( ) => {
120+ const c = new Counter ( ) ;
94121 tests . forEach ( test => {
95122 const result = extractCompilerPathAndArgs ( test [ 1 ] , test [ 0 ] , test [ 2 ] ) ;
96- equal ( result . compilerName , test [ 3 ] , 'compilerName should match' ) ;
97- deepEqual ( result . allCompilerArgs , test [ 4 ] , 'allCompilerArgs should match' ) ;
98- equal ( result . error , undefined , 'error should be undefined' ) ;
99- equal ( result . telemetry , undefined , 'telemetry should be undefined' ) ;
123+ equal ( result . compilerName , test [ 3 ] , `${ c . str } compilerName should match` ) ;
124+ deepEqual ( result . allCompilerArgs , test [ 4 ] , `${ c . str } allCompilerArgs should match` ) ;
125+ equal ( result . error , undefined , `${ c . str } error should be undefined` ) ;
126+ equal ( result . telemetry , undefined , `${ c . str } telemetry should be undefined` ) ;
127+ c . next ( ) ;
100128 } ) ;
101129 } ) ;
102130
@@ -113,27 +141,31 @@ if (isWindows) {
113141 [ `${ path . join ( 'bin' , 'gcc' ) } -O2` , true , undefined , 'gcc' , [ '-O2' ] ]
114142 ] ;
115143 it ( 'Verify various compilerPath strings with args' , ( ) => {
144+ const c = new Counter ( ) ;
116145 argsTests . forEach ( test => {
117146 const result = extractCompilerPathAndArgs ( test [ 1 ] , test [ 0 ] , test [ 2 ] ) ;
118- equal ( result . compilerName , test [ 3 ] , 'compilerName should match' ) ;
119- deepEqual ( result . allCompilerArgs , test [ 4 ] , 'allCompilerArgs should match' ) ;
120- equal ( result . error , undefined , 'error should be undefined' ) ;
121- equal ( result . telemetry , undefined , 'telemetry should be undefined' ) ;
147+ equal ( result . compilerName , test [ 3 ] , `${ c . str } compilerName should match` ) ;
148+ deepEqual ( result . allCompilerArgs , test [ 4 ] , `${ c . str } allCompilerArgs should match` ) ;
149+ equal ( result . error , undefined , `${ c . str } error should be undefined` ) ;
150+ equal ( result . telemetry , undefined , `${ c . str } telemetry should be undefined` ) ;
151+ c . next ( ) ;
122152 } ) ;
123153 } ) ;
124154
125155 const negativeTests : [ string , boolean , string [ ] | undefined , string , string [ ] ] [ ] = [
126156 [ `${ path . join ( assetsFolderFsPath , 'b i n' , 'clang++' ) } -std=c++20` , false , undefined , 'b' , [ 'i' , 'n/clang++' , '-std=c++20' ] ]
127157 ] ;
128158 it ( 'Verify various compilerPath strings with args that should fail' , ( ) => {
159+ const c = new Counter ( ) ;
129160 negativeTests . forEach ( test => {
130161 const result = extractCompilerPathAndArgs ( test [ 1 ] , test [ 0 ] , test [ 2 ] ) ;
131- equal ( result . compilerName , test [ 3 ] , ' compilerName should match' ) ;
132- deepEqual ( result . allCompilerArgs , test [ 4 ] , ' allCompilerArgs should match' ) ;
162+ equal ( result . compilerName , test [ 3 ] , ` ${ c . str } compilerName should match` ) ;
163+ deepEqual ( result . allCompilerArgs , test [ 4 ] , ` ${ c . str } allCompilerArgs should match` ) ;
133164
134165 // errors and telemetry are set by validateCompilerPath
135- equal ( result . error , undefined , 'error should be undefined' ) ;
136- equal ( result . telemetry , undefined , 'telemetry should be undefined' ) ;
166+ equal ( result . error , undefined , `${ c . str } error should be undefined` ) ;
167+ equal ( result . telemetry , undefined , `${ c . str } telemetry should be undefined` ) ;
168+ c . next ( ) ;
137169 } ) ;
138170 } ) ;
139171 } ) ;
@@ -155,17 +187,17 @@ describe('validateCompilerPath', () => {
155187 [ ' cl.exe ' , assetsFolder , 'cl.exe' , [ ] ]
156188 ] ;
157189 it ( 'Verify various compilerPath strings without args' , ( ) => {
158- let index = - 1 ;
190+ const c = new Counter ( ) ;
159191 tests . forEach ( test => {
160- index ++ ;
161- if ( ! isWindows && test [ 0 ] . includes ( 'clang-cl' ) ) {
162- return ; // This test is for checking the addition of .exe to the compiler name on Windows only.
192+ // Skip the clang-cl test on non-Windows. That test is for checking the addition of .exe to the compiler name on Windows only.
193+ if ( isWindows || ! test [ 0 ] . includes ( 'clang-cl' ) ) {
194+ const result = CppProperties . validateCompilerPath ( test [ 0 ] , test [ 1 ] ) ;
195+ equal ( result . compilerName , test [ 2 ] , `${ c . str } compilerName should match` ) ;
196+ deepEqual ( result . allCompilerArgs , test [ 3 ] , `${ c . str } allCompilerArgs should match` ) ;
197+ equal ( result . error , undefined , `${ c . str } error should be undefined` ) ;
198+ deepEqual ( result . telemetry , test [ 0 ] === '' ? undefined : { } , `${ c . str } telemetry should be empty` ) ;
163199 }
164- const result = CppProperties . validateCompilerPath ( test [ 0 ] , test [ 1 ] ) ;
165- equal ( result . compilerName , test [ 2 ] , `(test ${ index } ) compilerName should match` ) ;
166- deepEqual ( result . allCompilerArgs , test [ 3 ] , `(test ${ index } ) allCompilerArgs should match` ) ;
167- equal ( result . error , undefined , `(test ${ index } ) error should be undefined` ) ;
168- deepEqual ( result . telemetry , test [ 0 ] === '' ? undefined : { } , `(test ${ index } ) telemetry should be empty` ) ;
200+ c . next ( ) ;
169201 } ) ;
170202 } ) ;
171203
@@ -176,14 +208,14 @@ describe('validateCompilerPath', () => {
176208 [ 'clang -O2 -Wall' , assetsFolder , 'clang' , [ '-O2' , '-Wall' ] ]
177209 ] ;
178210 it ( 'Verify various compilerPath strings with args' , ( ) => {
179- let index = - 1 ;
211+ const c = new Counter ( ) ;
180212 argsTests . forEach ( test => {
181- index ++ ;
182213 const result = CppProperties . validateCompilerPath ( test [ 0 ] , test [ 1 ] ) ;
183- equal ( result . compilerName , test [ 2 ] , `(test ${ index } ) compilerName should match` ) ;
184- deepEqual ( result . allCompilerArgs , test [ 3 ] , `(test ${ index } ) allCompilerArgs should match` ) ;
185- equal ( result . error , undefined , `(test ${ index } error should be undefined` ) ;
186- deepEqual ( result . telemetry , { } , `(test ${ index } ) telemetry should be empty` ) ;
214+ equal ( result . compilerName , test [ 2 ] , `${ c . str } compilerName should match` ) ;
215+ deepEqual ( result . allCompilerArgs , test [ 3 ] , `${ c . str } allCompilerArgs should match` ) ;
216+ equal ( result . error , undefined , `${ c . str } error should be undefined` ) ;
217+ deepEqual ( result . telemetry , { } , `${ c . str } telemetry should be empty` ) ;
218+ c . next ( ) ;
187219 } ) ;
188220 } ) ;
189221
@@ -194,6 +226,7 @@ describe('validateCompilerPath', () => {
194226 ok ( result . error ?. includes ( 'Cannot find' ) , 'Should have an error for relative paths' ) ;
195227 equal ( result . telemetry ?. PathNonExistent , 1 , 'Should have telemetry for relative paths' ) ;
196228 equal ( result . telemetry ?. PathNotAFile , undefined , 'Should not have telemetry for invalid paths' ) ;
229+ equal ( result . telemetry ?. CompilerPathMissingQuotes , undefined , 'Should not have telemetry for missing quotes' ) ;
197230 } ) ;
198231
199232 it ( 'Verify errors with invalid absolute compiler path' , async ( ) => {
@@ -203,6 +236,7 @@ describe('validateCompilerPath', () => {
203236 ok ( result . error ?. includes ( 'Cannot find' ) , 'Should have an error for absolute paths' ) ;
204237 equal ( result . telemetry ?. PathNonExistent , 1 , 'Should have telemetry for absolute paths' ) ;
205238 equal ( result . telemetry ?. PathNotAFile , undefined , 'Should not have telemetry for invalid paths' ) ;
239+ equal ( result . telemetry ?. CompilerPathMissingQuotes , undefined , 'Should not have telemetry for missing quotes' ) ;
206240 } ) ;
207241
208242 it ( 'Verify errors with non-file compilerPath' , async ( ) => {
@@ -212,6 +246,7 @@ describe('validateCompilerPath', () => {
212246 ok ( result . error ?. includes ( 'Path is not a file' ) , 'Should have an error for non-file paths' ) ;
213247 equal ( result . telemetry ?. PathNonExistent , undefined , 'Should not have telemetry for relative paths' ) ;
214248 equal ( result . telemetry ?. PathNotAFile , 1 , 'Should have telemetry for invalid paths' ) ;
249+ equal ( result . telemetry ?. CompilerPathMissingQuotes , undefined , 'Should not have telemetry for missing quotes' ) ;
215250 } ) ;
216251
217252 it ( 'Verify errors with unknown compiler not in Path' , async ( ) => {
@@ -220,6 +255,7 @@ describe('validateCompilerPath', () => {
220255 equal ( result . allCompilerArgs . length , 0 , 'Should not have any args' ) ;
221256 equal ( result . telemetry ?. PathNonExistent , 1 , 'Should have telemetry for relative paths' ) ;
222257 equal ( result . telemetry ?. PathNotAFile , undefined , 'Should not have telemetry for invalid paths' ) ;
258+ equal ( result . telemetry ?. CompilerPathMissingQuotes , undefined , 'Should not have telemetry for missing quotes' ) ;
223259 } ) ;
224260
225261 it ( 'Verify errors with unknown compiler not in Path with args' , async ( ) => {
0 commit comments