@@ -11,6 +11,7 @@ import * as sinon from "sinon";
11
11
import * as platform from "../../src/platform" ;
12
12
import * as fs from "fs" ; // NOTE: Necessary for mock-fs.
13
13
import * as vscode from "vscode" ;
14
+ import { stripQuotePair } from "../../src/utils" ;
14
15
15
16
// We have to rewire the platform module so that mock-fs can be used, as it
16
17
// overrides the fs module but not the vscode.workspace.fs module.
@@ -34,7 +35,8 @@ async function fakeReadDirectory(targetPath: string | vscode.Uri): Promise<strin
34
35
const utilsMock = {
35
36
checkIfFileExists : fakeCheckIfFileOrDirectoryExists ,
36
37
checkIfDirectoryExists : fakeCheckIfFileOrDirectoryExists ,
37
- readDirectory : fakeReadDirectory
38
+ readDirectory : fakeReadDirectory ,
39
+ stripQuotePair : stripQuotePair
38
40
} ;
39
41
40
42
platformMock . __set__ ( "utils" , utilsMock ) ;
@@ -62,6 +64,9 @@ interface ITestPlatformSuccessCase extends ITestPlatform {
62
64
// Platform configurations where we expect to find a set of PowerShells
63
65
let successTestCases : ITestPlatformSuccessCase [ ] ;
64
66
67
+ // Platform configurations for testing the powerShellAdditionalExePaths setting
68
+ let additionalPowerShellExes : Record < string , string > ;
69
+ let successAdditionalTestCases : ITestPlatformSuccessCase [ ] ;
65
70
66
71
if ( process . platform === "win32" ) {
67
72
const msixAppDir = path . join ( process . env . LOCALAPPDATA ! , "Microsoft" , "WindowsApps" ) ;
@@ -443,8 +448,105 @@ if (process.platform === "win32") {
443
448
} ,
444
449
} ,
445
450
] ;
451
+
452
+ additionalPowerShellExes = {
453
+ "pwsh" : "C:\\Users\\test\\pwsh\\pwsh.exe" ,
454
+ "pwsh-no-exe" : "C:\\Users\\test\\pwsh\\pwsh" ,
455
+ "pwsh-folder" : "C:\\Users\\test\\pwsh\\" ,
456
+ "pwsh-folder-no-slash" : "C:\\Users\\test\\pwsh" ,
457
+ "pwsh-single-quotes" : "'C:\\Users\\test\\pwsh\\pwsh.exe'" ,
458
+ "pwsh-double-quotes" : "\"C:\\Users\\test\\pwsh\\pwsh.exe\"" ,
459
+ } ;
460
+
461
+ successAdditionalTestCases = [
462
+ {
463
+ name : "Windows (Additional PowerShell Executables)" ,
464
+ platformDetails : {
465
+ operatingSystem : platform . OperatingSystem . Windows ,
466
+ isOS64Bit : true ,
467
+ isProcess64Bit : true ,
468
+ } ,
469
+ environmentVars : {
470
+ "USERPROFILE" : "C:\\Users\\test" ,
471
+ } ,
472
+ expectedPowerShellSequence : [
473
+ {
474
+ exePath : "C:\\Users\\test\\pwsh\\pwsh.exe" ,
475
+ displayName : "pwsh" ,
476
+ supportsProperArguments : true
477
+ } ,
478
+ {
479
+ exePath : "C:\\Users\\test\\pwsh\\pwsh" ,
480
+ displayName : "pwsh-no-exe" ,
481
+ supportsProperArguments : true
482
+ } ,
483
+ {
484
+ exePath : "C:\\Users\\test\\pwsh\\pwsh.exe" ,
485
+ displayName : "pwsh-no-exe" ,
486
+ supportsProperArguments : true
487
+ } ,
488
+ {
489
+ exePath : "C:\\Users\\test\\pwsh\\pwsh\\pwsh.exe" ,
490
+ displayName : "pwsh-no-exe" ,
491
+ supportsProperArguments : true
492
+ } ,
493
+ {
494
+ exePath : "C:\\Users\\test\\pwsh\\pwsh\\powershell.exe" ,
495
+ displayName : "pwsh-no-exe" ,
496
+ supportsProperArguments : true
497
+ } ,
498
+ {
499
+ exePath : "C:\\Users\\test\\pwsh\\" ,
500
+ displayName : "pwsh-folder" ,
501
+ supportsProperArguments : true
502
+ } ,
503
+ {
504
+ exePath : "C:\\Users\\test\\pwsh\\pwsh.exe" ,
505
+ displayName : "pwsh-folder" ,
506
+ supportsProperArguments : true
507
+ } ,
508
+ {
509
+ exePath : "C:\\Users\\test\\pwsh\\powershell.exe" ,
510
+ displayName : "pwsh-folder" ,
511
+ supportsProperArguments : true
512
+ } ,
513
+ {
514
+ exePath : "C:\\Users\\test\\pwsh" ,
515
+ displayName : "pwsh-folder-no-slash" ,
516
+ supportsProperArguments : true
517
+ } ,
518
+ {
519
+ exePath : "C:\\Users\\test\\pwsh.exe" ,
520
+ displayName : "pwsh-folder-no-slash" ,
521
+ supportsProperArguments : true
522
+ } ,
523
+ {
524
+ exePath : "C:\\Users\\test\\pwsh\\pwsh.exe" ,
525
+ displayName : "pwsh-folder-no-slash" ,
526
+ supportsProperArguments : true
527
+ } ,
528
+ {
529
+ exePath : "C:\\Users\\test\\pwsh\\powershell.exe" ,
530
+ displayName : "pwsh-folder-no-slash" ,
531
+ supportsProperArguments : true
532
+ } ,
533
+ {
534
+ exePath : "C:\\Users\\test\\pwsh\\pwsh.exe" ,
535
+ displayName : "pwsh-single-quotes" ,
536
+ supportsProperArguments : true
537
+ } ,
538
+ {
539
+ exePath : "C:\\Users\\test\\pwsh\\pwsh.exe" ,
540
+ displayName : "pwsh-double-quotes" ,
541
+ supportsProperArguments : true
542
+ } ,
543
+ ] ,
544
+ filesystem : { } ,
545
+ }
546
+ ] ;
446
547
} else {
447
548
const pwshDailyDir = path . join ( os . homedir ( ) , ".powershell-daily" ) ;
549
+
448
550
successTestCases = [
449
551
{
450
552
name : "Linux (all installations)" ,
@@ -642,6 +744,66 @@ if (process.platform === "win32") {
642
744
} ,
643
745
} ,
644
746
] ;
747
+
748
+ additionalPowerShellExes = {
749
+ "pwsh" : "/home/bin/pwsh" ,
750
+ "pwsh-folder" : "/home/bin/" ,
751
+ "pwsh-folder-no-slash" : "/home/bin" ,
752
+ "pwsh-single-quotes" : "'/home/bin/pwsh'" ,
753
+ "pwsh-double-quotes" : "\"/home/bin/pwsh\"" ,
754
+ } ;
755
+
756
+ successAdditionalTestCases = [
757
+ { // Also sufficient for macOS as the behavior is the same
758
+ name : "Linux (Additional PowerShell Executables)" ,
759
+ platformDetails : {
760
+ operatingSystem : platform . OperatingSystem . Linux ,
761
+ isOS64Bit : true ,
762
+ isProcess64Bit : true ,
763
+ } ,
764
+ environmentVars : {
765
+ "HOME" : "/home/test" ,
766
+ } ,
767
+ expectedPowerShellSequence : [
768
+ {
769
+ exePath : "/home/bin/pwsh" ,
770
+ displayName : "pwsh" ,
771
+ supportsProperArguments : true
772
+ } ,
773
+ {
774
+ exePath : "/home/bin/" ,
775
+ displayName : "pwsh-folder" ,
776
+ supportsProperArguments : true
777
+ } ,
778
+ {
779
+ exePath : "/home/bin/pwsh" ,
780
+ displayName : "pwsh-folder" ,
781
+ supportsProperArguments : true
782
+ } ,
783
+ {
784
+ exePath : "/home/bin" ,
785
+ displayName : "pwsh-folder-no-slash" ,
786
+ supportsProperArguments : true
787
+ } ,
788
+ {
789
+ exePath : "/home/bin/pwsh" ,
790
+ displayName : "pwsh-folder-no-slash" ,
791
+ supportsProperArguments : true
792
+ } ,
793
+ {
794
+ exePath : "/home/bin/pwsh" ,
795
+ displayName : "pwsh-single-quotes" ,
796
+ supportsProperArguments : true
797
+ } ,
798
+ {
799
+ exePath : "/home/bin/pwsh" ,
800
+ displayName : "pwsh-double-quotes" ,
801
+ supportsProperArguments : true
802
+ } ,
803
+ ] ,
804
+ filesystem : { } ,
805
+ }
806
+ ] ;
645
807
}
646
808
647
809
const errorTestCases : ITestPlatform [ ] = [
@@ -846,4 +1008,28 @@ describe("Platform module", function () {
846
1008
} ) ;
847
1009
}
848
1010
} ) ;
1011
+
1012
+ describe ( "PowerShell executables from 'powerShellAdditionalExePaths' are found" , function ( ) {
1013
+ afterEach ( function ( ) {
1014
+ sinon . restore ( ) ;
1015
+ mockFS . restore ( ) ;
1016
+ } ) ;
1017
+
1018
+ for ( const testPlatform of successAdditionalTestCases ) {
1019
+ it ( `Guesses for ${ testPlatform . name } ` , function ( ) {
1020
+ setupTestEnvironment ( testPlatform ) ;
1021
+
1022
+ const powerShellExeFinder = new platformMock . PowerShellExeFinder ( testPlatform . platformDetails , additionalPowerShellExes ) ;
1023
+
1024
+ let i = 0 ;
1025
+ for ( const additionalPwsh of powerShellExeFinder . enumerateAdditionalPowerShellInstallations ( ) ) {
1026
+ const expectedPowerShell = testPlatform . expectedPowerShellSequence [ i ] ;
1027
+ i ++ ;
1028
+
1029
+ assert . strictEqual ( additionalPwsh . exePath , expectedPowerShell . exePath ) ;
1030
+ assert . strictEqual ( additionalPwsh . displayName , expectedPowerShell . displayName ) ;
1031
+ }
1032
+ } ) ;
1033
+ }
1034
+ } ) ;
849
1035
} ) ;
0 commit comments