|
| 1 | +/*--------------------------------------------------------- |
| 2 | + * Copyright (C) Microsoft Corporation. All rights reserved. |
| 3 | + *--------------------------------------------------------*/ |
| 4 | + |
| 5 | +import * as assert from 'assert'; |
| 6 | +import * as vscode from 'vscode'; |
| 7 | +import * as platform from '../src/platform'; |
| 8 | + |
| 9 | +function checkDefaultPowerShellPath(platformDetails, expectedPath) { |
| 10 | + test("returns correct default path", () => { |
| 11 | + assert.equal( |
| 12 | + platform.getDefaultPowerShellPath(platformDetails), |
| 13 | + expectedPath); |
| 14 | + }); |
| 15 | +} |
| 16 | + |
| 17 | +function checkAvailableWindowsPowerShellPaths( |
| 18 | + platformDetails: platform.PlatformDetails, |
| 19 | + expectedPaths: platform.PowerShellExeDetails[]) { |
| 20 | + test("correctly enumerates available Windows PowerShell paths", () => { |
| 21 | + |
| 22 | + // The system may return PowerShell Core paths so only |
| 23 | + // enumerate the first list items. |
| 24 | + let enumeratedPaths = platform.getAvailablePowerShellExes(platformDetails); |
| 25 | + for (var i; i < expectedPaths.length; i++) { |
| 26 | + assert.equal(enumeratedPaths[i], expectedPaths[i]); |
| 27 | + } |
| 28 | + }); |
| 29 | +} |
| 30 | + |
| 31 | +function checkFixedWindowsPowerShellpath(platformDetails, inputPath, expectedPath) { |
| 32 | + test("fixes incorrect Windows PowerShell Sys* path", () => { |
| 33 | + assert.equal( |
| 34 | + platform.fixWindowsPowerShellPath(inputPath, platformDetails), |
| 35 | + expectedPath); |
| 36 | + }); |
| 37 | +} |
| 38 | + |
| 39 | +suite("Platform module", () => { |
| 40 | + |
| 41 | + suite("64-bit Windows, 64-bit VS Code", () => { |
| 42 | + let platformDetails: platform.PlatformDetails = { |
| 43 | + operatingSystem: platform.OperatingSystem.Windows, |
| 44 | + isOS64Bit: true, |
| 45 | + isProcess64Bit: true |
| 46 | + }; |
| 47 | + |
| 48 | + checkDefaultPowerShellPath( |
| 49 | + platformDetails, |
| 50 | + platform.System32PowerShellPath); |
| 51 | + |
| 52 | + checkAvailableWindowsPowerShellPaths( |
| 53 | + platformDetails, |
| 54 | + [ |
| 55 | + { |
| 56 | + versionName: platform.WindowsPowerShell64BitLabel, |
| 57 | + exePath: platform.System32PowerShellPath |
| 58 | + }, |
| 59 | + { |
| 60 | + versionName: platform.WindowsPowerShell32BitLabel, |
| 61 | + exePath: platform.SysWow64PowerShellPath |
| 62 | + } |
| 63 | + ]); |
| 64 | + |
| 65 | + checkFixedWindowsPowerShellpath( |
| 66 | + platformDetails, |
| 67 | + platform.SysnativePowerShellPath, |
| 68 | + platform.System32PowerShellPath); |
| 69 | + }); |
| 70 | + |
| 71 | + suite("64-bit Windows, 32-bit VS Code", () => { |
| 72 | + let platformDetails: platform.PlatformDetails = { |
| 73 | + operatingSystem: platform.OperatingSystem.Windows, |
| 74 | + isOS64Bit: true, |
| 75 | + isProcess64Bit: false |
| 76 | + }; |
| 77 | + |
| 78 | + checkDefaultPowerShellPath( |
| 79 | + platformDetails, |
| 80 | + platform.SysnativePowerShellPath); |
| 81 | + |
| 82 | + checkAvailableWindowsPowerShellPaths( |
| 83 | + platformDetails, |
| 84 | + [ |
| 85 | + { |
| 86 | + versionName: platform.WindowsPowerShell64BitLabel, |
| 87 | + exePath: platform.SysnativePowerShellPath |
| 88 | + }, |
| 89 | + { |
| 90 | + versionName: platform.WindowsPowerShell32BitLabel, |
| 91 | + exePath: platform.System32PowerShellPath |
| 92 | + } |
| 93 | + ]); |
| 94 | + |
| 95 | + checkFixedWindowsPowerShellpath( |
| 96 | + platformDetails, |
| 97 | + platform.SysWow64PowerShellPath, |
| 98 | + platform.System32PowerShellPath); |
| 99 | + }); |
| 100 | + |
| 101 | + suite("32-bit Windows, 32-bit VS Code", () => { |
| 102 | + let platformDetails: platform.PlatformDetails = { |
| 103 | + operatingSystem: platform.OperatingSystem.Windows, |
| 104 | + isOS64Bit: false, |
| 105 | + isProcess64Bit: false |
| 106 | + }; |
| 107 | + |
| 108 | + checkDefaultPowerShellPath( |
| 109 | + platformDetails, |
| 110 | + platform.System32PowerShellPath); |
| 111 | + |
| 112 | + checkAvailableWindowsPowerShellPaths( |
| 113 | + platformDetails, |
| 114 | + [ |
| 115 | + { |
| 116 | + versionName: platform.WindowsPowerShell32BitLabel, |
| 117 | + exePath: platform.System32PowerShellPath |
| 118 | + } |
| 119 | + ]); |
| 120 | + }); |
| 121 | +}); |
0 commit comments