-
Notifications
You must be signed in to change notification settings - Fork 526
Expand file tree
/
Copy pathinstallCommand.test.ts
More file actions
134 lines (122 loc) · 4.51 KB
/
installCommand.test.ts
File metadata and controls
134 lines (122 loc) · 4.51 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import { expect } from 'chai';
/**
* Mirror of the install command construction logic from CMakeDriver.getCMakeInstallCommand().
* Backend tests cannot import modules that depend on 'vscode', so we mirror the pure
* command-construction logic here. If the driver implementation changes, update this mirror
* to match. See also: targetMap.test.ts and shell-propagation.test.ts for the same pattern.
*/
interface BuildCommand {
command: string;
args: string[];
build_env: Record<string, string>;
}
interface InstallCommandParams {
cmakePath: string;
binaryDir: string;
isMultiConf: boolean;
currentBuildType: string;
installDir: string | null;
supportsInstallCommand: boolean;
}
function getCMakeInstallCommand(params: InstallCommandParams): BuildCommand | null {
if (!params.supportsInstallCommand) {
return null;
}
const args: string[] = ['--install', params.binaryDir];
if (params.isMultiConf) {
args.push('--config', params.currentBuildType);
}
if (params.installDir) {
args.push('--prefix', params.installDir);
}
return { command: params.cmakePath, args, build_env: {} };
}
suite('[Install Command Construction]', () => {
test('basic install command for single-config generator', () => {
const cmd = getCMakeInstallCommand({
cmakePath: '/usr/bin/cmake',
binaryDir: '/home/user/project/build',
isMultiConf: false,
currentBuildType: 'Release',
installDir: null,
supportsInstallCommand: true
});
expect(cmd).to.not.be.null;
expect(cmd!.command).to.equal('/usr/bin/cmake');
expect(cmd!.args).to.deep.equal(['--install', '/home/user/project/build']);
});
test('install command includes --config for multi-config generator', () => {
const cmd = getCMakeInstallCommand({
cmakePath: '/usr/bin/cmake',
binaryDir: '/home/user/project/build',
isMultiConf: true,
currentBuildType: 'Debug',
installDir: null,
supportsInstallCommand: true
});
expect(cmd).to.not.be.null;
expect(cmd!.args).to.deep.equal([
'--install', '/home/user/project/build',
'--config', 'Debug'
]);
});
test('install command includes --prefix when installDir is set', () => {
const cmd = getCMakeInstallCommand({
cmakePath: '/usr/bin/cmake',
binaryDir: '/home/user/project/build',
isMultiConf: false,
currentBuildType: 'Release',
installDir: '/home/user/project/_install',
supportsInstallCommand: true
});
expect(cmd).to.not.be.null;
expect(cmd!.args).to.deep.equal([
'--install', '/home/user/project/build',
'--prefix', '/home/user/project/_install'
]);
});
test('install command includes both --config and --prefix when needed', () => {
const cmd = getCMakeInstallCommand({
cmakePath: 'C:\\cmake\\bin\\cmake.exe',
binaryDir: 'C:\\project\\build',
isMultiConf: true,
currentBuildType: 'Release',
installDir: 'C:\\project\\_install',
supportsInstallCommand: true
});
expect(cmd).to.not.be.null;
expect(cmd!.args).to.deep.equal([
'--install', 'C:\\project\\build',
'--config', 'Release',
'--prefix', 'C:\\project\\_install'
]);
});
test('returns null when cmake version does not support --install', () => {
const cmd = getCMakeInstallCommand({
cmakePath: '/usr/bin/cmake',
binaryDir: '/home/user/project/build',
isMultiConf: false,
currentBuildType: 'Release',
installDir: null,
supportsInstallCommand: false
});
expect(cmd).to.be.null;
});
test('installDir null does not produce --prefix', () => {
const cmd = getCMakeInstallCommand({
cmakePath: '/usr/bin/cmake',
binaryDir: '/build',
isMultiConf: true,
currentBuildType: 'RelWithDebInfo',
installDir: null,
supportsInstallCommand: true
});
expect(cmd).to.not.be.null;
expect(cmd!.args).to.deep.equal([
'--install', '/build',
'--config', 'RelWithDebInfo'
]);
// Ensure no --prefix argument when installDir is null
expect(cmd!.args).to.not.include('--prefix');
});
});