4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
6
import { deepStrictEqual , ok , strictEqual } from 'assert' ;
7
- import { userInfo } from 'os' ;
7
+ import { homedir , userInfo } from 'os' ;
8
8
import { NullLogService } from 'vs/platform/log/common/log' ;
9
9
import { ITerminalProcessOptions } from 'vs/platform/terminal/common/terminal' ;
10
10
import { getShellIntegrationInjection , IShellIntegrationConfigInjection } from 'vs/platform/terminal/node/terminalEnvironment' ;
@@ -14,13 +14,14 @@ const disabledProcessOptions: ITerminalProcessOptions['shellIntegration'] = { en
14
14
const pwshExe = process . platform === 'win32' ? 'pwsh.exe' : 'pwsh' ;
15
15
const repoRoot = process . platform === 'win32' ? process . cwd ( ) [ 0 ] . toLowerCase ( ) + process . cwd ( ) . substring ( 1 ) : process . cwd ( ) ;
16
16
const logService = new NullLogService ( ) ;
17
+ const defaultEnvironment = { } ;
17
18
18
19
suite ( 'platform - terminalEnvironment' , ( ) => {
19
20
suite ( 'getShellIntegrationInjection' , ( ) => {
20
21
suite ( 'should not enable' , ( ) => {
21
22
test ( 'when isFeatureTerminal or when no executable is provided' , ( ) => {
22
- ok ( ! getShellIntegrationInjection ( { executable : pwshExe , args : [ '-l' , '-NoLogo' ] , isFeatureTerminal : true } , enabledProcessOptions , logService ) ) ;
23
- ok ( getShellIntegrationInjection ( { executable : pwshExe , args : [ '-l' , '-NoLogo' ] , isFeatureTerminal : false } , enabledProcessOptions , logService ) ) ;
23
+ ok ( ! getShellIntegrationInjection ( { executable : pwshExe , args : [ '-l' , '-NoLogo' ] , isFeatureTerminal : true } , enabledProcessOptions , defaultEnvironment , logService ) ) ;
24
+ ok ( getShellIntegrationInjection ( { executable : pwshExe , args : [ '-l' , '-NoLogo' ] , isFeatureTerminal : false } , enabledProcessOptions , defaultEnvironment , logService ) ) ;
24
25
} ) ;
25
26
} ) ;
26
27
@@ -40,21 +41,21 @@ suite('platform - terminalEnvironment', () => {
40
41
}
41
42
} ) ;
42
43
test ( 'when undefined, []' , ( ) => {
43
- deepStrictEqual ( getShellIntegrationInjection ( { executable : pwshExe , args : [ ] } , enabledProcessOptions , logService ) , enabledExpectedResult ) ;
44
- deepStrictEqual ( getShellIntegrationInjection ( { executable : pwshExe , args : undefined } , enabledProcessOptions , logService ) , enabledExpectedResult ) ;
44
+ deepStrictEqual ( getShellIntegrationInjection ( { executable : pwshExe , args : [ ] } , enabledProcessOptions , defaultEnvironment , logService ) , enabledExpectedResult ) ;
45
+ deepStrictEqual ( getShellIntegrationInjection ( { executable : pwshExe , args : undefined } , enabledProcessOptions , defaultEnvironment , logService ) , enabledExpectedResult ) ;
45
46
} ) ;
46
47
suite ( 'when no logo' , ( ) => {
47
48
test ( 'array - case insensitive' , ( ) => {
48
- deepStrictEqual ( getShellIntegrationInjection ( { executable : pwshExe , args : [ '-NoLogo' ] } , enabledProcessOptions , logService ) , enabledExpectedResult ) ;
49
- deepStrictEqual ( getShellIntegrationInjection ( { executable : pwshExe , args : [ '-NOLOGO' ] } , enabledProcessOptions , logService ) , enabledExpectedResult ) ;
50
- deepStrictEqual ( getShellIntegrationInjection ( { executable : pwshExe , args : [ '-nol' ] } , enabledProcessOptions , logService ) , enabledExpectedResult ) ;
51
- deepStrictEqual ( getShellIntegrationInjection ( { executable : pwshExe , args : [ '-NOL' ] } , enabledProcessOptions , logService ) , enabledExpectedResult ) ;
49
+ deepStrictEqual ( getShellIntegrationInjection ( { executable : pwshExe , args : [ '-NoLogo' ] } , enabledProcessOptions , defaultEnvironment , logService ) , enabledExpectedResult ) ;
50
+ deepStrictEqual ( getShellIntegrationInjection ( { executable : pwshExe , args : [ '-NOLOGO' ] } , enabledProcessOptions , defaultEnvironment , logService ) , enabledExpectedResult ) ;
51
+ deepStrictEqual ( getShellIntegrationInjection ( { executable : pwshExe , args : [ '-nol' ] } , enabledProcessOptions , defaultEnvironment , logService ) , enabledExpectedResult ) ;
52
+ deepStrictEqual ( getShellIntegrationInjection ( { executable : pwshExe , args : [ '-NOL' ] } , enabledProcessOptions , defaultEnvironment , logService ) , enabledExpectedResult ) ;
52
53
} ) ;
53
54
test ( 'string - case insensitive' , ( ) => {
54
- deepStrictEqual ( getShellIntegrationInjection ( { executable : pwshExe , args : '-NoLogo' } , enabledProcessOptions , logService ) , enabledExpectedResult ) ;
55
- deepStrictEqual ( getShellIntegrationInjection ( { executable : pwshExe , args : '-NOLOGO' } , enabledProcessOptions , logService ) , enabledExpectedResult ) ;
56
- deepStrictEqual ( getShellIntegrationInjection ( { executable : pwshExe , args : '-nol' } , enabledProcessOptions , logService ) , enabledExpectedResult ) ;
57
- deepStrictEqual ( getShellIntegrationInjection ( { executable : pwshExe , args : '-NOL' } , enabledProcessOptions , logService ) , enabledExpectedResult ) ;
55
+ deepStrictEqual ( getShellIntegrationInjection ( { executable : pwshExe , args : '-NoLogo' } , enabledProcessOptions , defaultEnvironment , logService ) , enabledExpectedResult ) ;
56
+ deepStrictEqual ( getShellIntegrationInjection ( { executable : pwshExe , args : '-NOLOGO' } , enabledProcessOptions , defaultEnvironment , logService ) , enabledExpectedResult ) ;
57
+ deepStrictEqual ( getShellIntegrationInjection ( { executable : pwshExe , args : '-nol' } , enabledProcessOptions , defaultEnvironment , logService ) , enabledExpectedResult ) ;
58
+ deepStrictEqual ( getShellIntegrationInjection ( { executable : pwshExe , args : '-NOL' } , enabledProcessOptions , defaultEnvironment , logService ) , enabledExpectedResult ) ;
58
59
} ) ;
59
60
} ) ;
60
61
} ) ;
@@ -71,23 +72,23 @@ suite('platform - terminalEnvironment', () => {
71
72
}
72
73
} ) ;
73
74
test ( 'when array contains no logo and login' , ( ) => {
74
- deepStrictEqual ( getShellIntegrationInjection ( { executable : pwshExe , args : [ '-l' , '-NoLogo' ] } , enabledProcessOptions , logService ) , enabledExpectedResult ) ;
75
+ deepStrictEqual ( getShellIntegrationInjection ( { executable : pwshExe , args : [ '-l' , '-NoLogo' ] } , enabledProcessOptions , defaultEnvironment , logService ) , enabledExpectedResult ) ;
75
76
} ) ;
76
77
test ( 'when string' , ( ) => {
77
- deepStrictEqual ( getShellIntegrationInjection ( { executable : pwshExe , args : '-l' } , enabledProcessOptions , logService ) , enabledExpectedResult ) ;
78
+ deepStrictEqual ( getShellIntegrationInjection ( { executable : pwshExe , args : '-l' } , enabledProcessOptions , defaultEnvironment , logService ) , enabledExpectedResult ) ;
78
79
} ) ;
79
80
} ) ;
80
81
suite ( 'should not modify args' , ( ) => {
81
82
test ( 'when shell integration is disabled' , ( ) => {
82
- strictEqual ( getShellIntegrationInjection ( { executable : pwshExe , args : [ '-l' ] } , disabledProcessOptions , logService ) , undefined ) ;
83
- strictEqual ( getShellIntegrationInjection ( { executable : pwshExe , args : '-l' } , disabledProcessOptions , logService ) , undefined ) ;
84
- strictEqual ( getShellIntegrationInjection ( { executable : pwshExe , args : undefined } , disabledProcessOptions , logService ) , undefined ) ;
83
+ strictEqual ( getShellIntegrationInjection ( { executable : pwshExe , args : [ '-l' ] } , disabledProcessOptions , defaultEnvironment , logService ) , undefined ) ;
84
+ strictEqual ( getShellIntegrationInjection ( { executable : pwshExe , args : '-l' } , disabledProcessOptions , defaultEnvironment , logService ) , undefined ) ;
85
+ strictEqual ( getShellIntegrationInjection ( { executable : pwshExe , args : undefined } , disabledProcessOptions , defaultEnvironment , logService ) , undefined ) ;
85
86
} ) ;
86
87
test ( 'when using unrecognized arg' , ( ) => {
87
- strictEqual ( getShellIntegrationInjection ( { executable : pwshExe , args : [ '-l' , '-NoLogo' , '-i' ] } , disabledProcessOptions , logService ) , undefined ) ;
88
+ strictEqual ( getShellIntegrationInjection ( { executable : pwshExe , args : [ '-l' , '-NoLogo' , '-i' ] } , disabledProcessOptions , defaultEnvironment , logService ) , undefined ) ;
88
89
} ) ;
89
90
test ( 'when using unrecognized arg (string)' , ( ) => {
90
- strictEqual ( getShellIntegrationInjection ( { executable : pwshExe , args : '-i' } , disabledProcessOptions , logService ) , undefined ) ;
91
+ strictEqual ( getShellIntegrationInjection ( { executable : pwshExe , args : '-i' } , disabledProcessOptions , defaultEnvironment , logService ) , undefined ) ;
91
92
} ) ;
92
93
} ) ;
93
94
} ) ;
@@ -97,6 +98,7 @@ suite('platform - terminalEnvironment', () => {
97
98
suite ( 'should override args' , ( ) => {
98
99
const username = userInfo ( ) . username ;
99
100
const expectedDir = new RegExp ( `.+\/${ username } -vscode-zsh` ) ;
101
+ const customZdotdir = '/custom/zsh/dotdir' ;
100
102
const expectedDests = [
101
103
new RegExp ( `.+\/${ username } -vscode-zsh\/\.zshrc` ) ,
102
104
new RegExp ( `.+\/${ username } -vscode-zsh\/\.zprofile` ) ,
@@ -109,9 +111,10 @@ suite('platform - terminalEnvironment', () => {
109
111
/ .+ \/ o u t \/ v s \/ w o r k b e n c h \/ c o n t r i b \/ t e r m i n a l \/ b r o w s e r \/ m e d i a \/ s h e l l I n t e g r a t i o n - e n v .z s h / ,
110
112
/ .+ \/ o u t \/ v s \/ w o r k b e n c h \/ c o n t r i b \/ t e r m i n a l \/ b r o w s e r \/ m e d i a \/ s h e l l I n t e g r a t i o n - l o g i n .z s h /
111
113
] ;
112
- function assertIsEnabled ( result : IShellIntegrationConfigInjection ) {
113
- strictEqual ( Object . keys ( result . envMixin ! ) . length , 2 ) ;
114
+ function assertIsEnabled ( result : IShellIntegrationConfigInjection , globalZdotdir = homedir ( ) ) {
115
+ strictEqual ( Object . keys ( result . envMixin ! ) . length , 3 ) ;
114
116
ok ( result . envMixin ! [ 'ZDOTDIR' ] ?. match ( expectedDir ) ) ;
117
+ strictEqual ( result . envMixin ! [ 'USER_ZDOTDIR' ] , globalZdotdir ) ;
115
118
ok ( result . envMixin ! [ 'VSCODE_INJECTION' ] ?. match ( '1' ) ) ;
116
119
strictEqual ( result . filesToCopy ?. length , 4 ) ;
117
120
ok ( result . filesToCopy [ 0 ] . dest . match ( expectedDests [ 0 ] ) ) ;
@@ -124,27 +127,39 @@ suite('platform - terminalEnvironment', () => {
124
127
ok ( result . filesToCopy [ 3 ] . source . match ( expectedSources [ 3 ] ) ) ;
125
128
}
126
129
test ( 'when undefined, []' , ( ) => {
127
- const result1 = getShellIntegrationInjection ( { executable : 'zsh' , args : [ ] } , enabledProcessOptions , logService ) ;
130
+ const result1 = getShellIntegrationInjection ( { executable : 'zsh' , args : [ ] } , enabledProcessOptions , defaultEnvironment , logService ) ;
128
131
deepStrictEqual ( result1 ?. newArgs , [ '-i' ] ) ;
129
132
assertIsEnabled ( result1 ) ;
130
- const result2 = getShellIntegrationInjection ( { executable : 'zsh' , args : undefined } , enabledProcessOptions , logService ) ;
133
+ const result2 = getShellIntegrationInjection ( { executable : 'zsh' , args : undefined } , enabledProcessOptions , defaultEnvironment , logService ) ;
131
134
deepStrictEqual ( result2 ?. newArgs , [ '-i' ] ) ;
132
135
assertIsEnabled ( result2 ) ;
133
136
} ) ;
134
137
suite ( 'should incorporate login arg' , ( ) => {
135
138
test ( 'when array' , ( ) => {
136
- const result = getShellIntegrationInjection ( { executable : 'zsh' , args : [ '-l' ] } , enabledProcessOptions , logService ) ;
139
+ const result = getShellIntegrationInjection ( { executable : 'zsh' , args : [ '-l' ] } , enabledProcessOptions , defaultEnvironment , logService ) ;
137
140
deepStrictEqual ( result ?. newArgs , [ '-il' ] ) ;
138
141
assertIsEnabled ( result ) ;
139
142
} ) ;
140
143
} ) ;
141
144
suite ( 'should not modify args' , ( ) => {
142
145
test ( 'when shell integration is disabled' , ( ) => {
143
- strictEqual ( getShellIntegrationInjection ( { executable : 'zsh' , args : [ '-l' ] } , disabledProcessOptions , logService ) , undefined ) ;
144
- strictEqual ( getShellIntegrationInjection ( { executable : 'zsh' , args : undefined } , disabledProcessOptions , logService ) , undefined ) ;
146
+ strictEqual ( getShellIntegrationInjection ( { executable : 'zsh' , args : [ '-l' ] } , disabledProcessOptions , defaultEnvironment , logService ) , undefined ) ;
147
+ strictEqual ( getShellIntegrationInjection ( { executable : 'zsh' , args : undefined } , disabledProcessOptions , defaultEnvironment , logService ) , undefined ) ;
145
148
} ) ;
146
149
test ( 'when using unrecognized arg' , ( ) => {
147
- strictEqual ( getShellIntegrationInjection ( { executable : 'zsh' , args : [ '-l' , '-fake' ] } , disabledProcessOptions , logService ) , undefined ) ;
150
+ strictEqual ( getShellIntegrationInjection ( { executable : 'zsh' , args : [ '-l' , '-fake' ] } , disabledProcessOptions , defaultEnvironment , logService ) , undefined ) ;
151
+ } ) ;
152
+ } ) ;
153
+ suite ( 'should incorporate global ZDOTDIR env variable' , ( ) => {
154
+ test ( 'when custom ZDOTDIR' , ( ) => {
155
+ const result1 = getShellIntegrationInjection ( { executable : 'zsh' , args : [ ] } , enabledProcessOptions , { ...defaultEnvironment , ZDOTDIR : customZdotdir } , logService ) ;
156
+ deepStrictEqual ( result1 ?. newArgs , [ '-i' ] ) ;
157
+ assertIsEnabled ( result1 , customZdotdir ) ;
158
+ } ) ;
159
+ test ( 'when undefined' , ( ) => {
160
+ const result1 = getShellIntegrationInjection ( { executable : 'zsh' , args : [ ] } , enabledProcessOptions , undefined , logService ) ;
161
+ deepStrictEqual ( result1 ?. newArgs , [ '-i' ] ) ;
162
+ assertIsEnabled ( result1 ) ;
148
163
} ) ;
149
164
} ) ;
150
165
} ) ;
@@ -161,9 +176,9 @@ suite('platform - terminalEnvironment', () => {
161
176
VSCODE_INJECTION : '1'
162
177
}
163
178
} ) ;
164
- deepStrictEqual ( getShellIntegrationInjection ( { executable : 'bash' , args : [ ] } , enabledProcessOptions , logService ) , enabledExpectedResult ) ;
165
- deepStrictEqual ( getShellIntegrationInjection ( { executable : 'bash' , args : '' } , enabledProcessOptions , logService ) , enabledExpectedResult ) ;
166
- deepStrictEqual ( getShellIntegrationInjection ( { executable : 'bash' , args : undefined } , enabledProcessOptions , logService ) , enabledExpectedResult ) ;
179
+ deepStrictEqual ( getShellIntegrationInjection ( { executable : 'bash' , args : [ ] } , enabledProcessOptions , defaultEnvironment , logService ) , enabledExpectedResult ) ;
180
+ deepStrictEqual ( getShellIntegrationInjection ( { executable : 'bash' , args : '' } , enabledProcessOptions , defaultEnvironment , logService ) , enabledExpectedResult ) ;
181
+ deepStrictEqual ( getShellIntegrationInjection ( { executable : 'bash' , args : undefined } , enabledProcessOptions , defaultEnvironment , logService ) , enabledExpectedResult ) ;
167
182
} ) ;
168
183
suite ( 'should set login env variable and not modify args' , ( ) => {
169
184
const enabledExpectedResult = Object . freeze < IShellIntegrationConfigInjection > ( {
@@ -177,16 +192,16 @@ suite('platform - terminalEnvironment', () => {
177
192
}
178
193
} ) ;
179
194
test ( 'when array' , ( ) => {
180
- deepStrictEqual ( getShellIntegrationInjection ( { executable : 'bash' , args : [ '-l' ] } , enabledProcessOptions , logService ) , enabledExpectedResult ) ;
195
+ deepStrictEqual ( getShellIntegrationInjection ( { executable : 'bash' , args : [ '-l' ] } , enabledProcessOptions , defaultEnvironment , logService ) , enabledExpectedResult ) ;
181
196
} ) ;
182
197
} ) ;
183
198
suite ( 'should not modify args' , ( ) => {
184
199
test ( 'when shell integration is disabled' , ( ) => {
185
- strictEqual ( getShellIntegrationInjection ( { executable : 'bash' , args : [ '-l' ] } , disabledProcessOptions , logService ) , undefined ) ;
186
- strictEqual ( getShellIntegrationInjection ( { executable : 'bash' , args : undefined } , disabledProcessOptions , logService ) , undefined ) ;
200
+ strictEqual ( getShellIntegrationInjection ( { executable : 'bash' , args : [ '-l' ] } , disabledProcessOptions , defaultEnvironment , logService ) , undefined ) ;
201
+ strictEqual ( getShellIntegrationInjection ( { executable : 'bash' , args : undefined } , disabledProcessOptions , defaultEnvironment , logService ) , undefined ) ;
187
202
} ) ;
188
203
test ( 'when custom array entry' , ( ) => {
189
- strictEqual ( getShellIntegrationInjection ( { executable : 'bash' , args : [ '-l' , '-i' ] } , disabledProcessOptions , logService ) , undefined ) ;
204
+ strictEqual ( getShellIntegrationInjection ( { executable : 'bash' , args : [ '-l' , '-i' ] } , disabledProcessOptions , defaultEnvironment , logService ) , undefined ) ;
190
205
} ) ;
191
206
} ) ;
192
207
} ) ;
0 commit comments