forked from microsoft/vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpowershell.test.ts
More file actions
58 lines (48 loc) · 1.97 KB
/
powershell.test.ts
File metadata and controls
58 lines (48 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import * as fs from 'fs';
import * as platform from 'vs/base/common/platform';
import { enumeratePowerShellInstallations, getFirstAvailablePowerShellInstallation, IPowerShellExeDetails } from 'vs/base/node/powershell';
function checkPath(exePath: string) {
// Check to see if the path exists
let pathCheckResult = false;
try {
const stat = fs.statSync(exePath);
pathCheckResult = stat.isFile();
} catch {
// fs.exists throws on Windows with SymbolicLinks so we
// also use lstat to try and see if the file exists.
try {
pathCheckResult = fs.statSync(fs.readlinkSync(exePath)).isFile();
} catch {
}
}
assert.strictEqual(pathCheckResult, true);
}
if (platform.isWindows) {
suite('PowerShell finder', () => {
test('Can find first available PowerShell', async () => {
const pwshExe = await getFirstAvailablePowerShellInstallation();
const exePath = pwshExe?.exePath;
assert.notStrictEqual(exePath, null);
assert.notStrictEqual(pwshExe?.displayName, null);
checkPath(exePath!);
});
test('Can enumerate PowerShells', async () => {
const pwshs = new Array<IPowerShellExeDetails>();
for await (const p of enumeratePowerShellInstallations()) {
pwshs.push(p);
}
const powershellLog = 'Found these PowerShells:\n' + pwshs.map(p => `${p.displayName}: ${p.exePath}`).join('\n');
assert.strictEqual(pwshs.length >= 1, true, powershellLog);
for (const pwsh of pwshs) {
checkPath(pwsh.exePath);
}
// The last one should always be Windows PowerShell.
assert.strictEqual(pwshs[pwshs.length - 1].displayName, 'Windows PowerShell', powershellLog);
});
});
}