blob: ee1b8575852cc48f297cbaa59f26fbdf070bddeb (
plain)
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
# Environment variable tests
#Test if variables can be properly set
set smurf blue
if test $smurf = blue
echo Test 1 pass
else
echo Test 1 fail
end
# Test if variables can be erased
set -e smurf
if test $smurf
echo Test 2 fail
else
echo Test 2 pass
end
# Test if local variables go out of scope
set -e t3
if true
set -l t3 bar
end
if test $t3
echo Test 3 fail
else
echo Test 3 pass
end
# Test if globals can be set in block scope
if true
set -g baz qux
end
if test $baz = qux
echo Test 4 pass
else
echo Test 4 fail
end
#Test that scope is preserved when setting a new value
set t5 a
if true
set t5 b
end
if test $t5 = b
echo Test 5 pass
else
echo Test 5 fail
end
# Test that scope is preserved in double blocks
for i in 1
set t6 $i
for j in a
if test $t6$j = 1a
echo Test 6 pass
else
echo Test 6 fail
end
end
end
# Test if variables in for loop blocks do not go out of scope on new laps
set res fail
set -e t7
for i in 1 2
if test $i = 1
set t7 lala
else
if test $t7
set res pass
end
end
end
echo Test 7 $res
# Test if variables are properly exported
set -e t8
if true
set -lx t8 foo
if test (../fish -c "echo $t8") = foo
echo Test 8 pass
else
echo Test 8 fail
end
end
# Test if exported variables go out of scope
if test (../fish -c "echo $t8")
echo Test 9 fail
else
echo Test 9 pass
end
# Test erasing variables in specific scope
set -eU __fish_test_universal_variables_variable_foo
set -g __fish_test_universal_variables_variable_foo bar
begin
set -l __fish_test_universal_variables_variable_foo baz
set -eg __fish_test_universal_variables_variable_foo
end
if set -q __fish_test_universal_variables_variable_foo
echo Test 10 fail
else
echo Test 10 pass
end
set __fish_test_universal_variables_variable_foo abc def
set -e __fish_test_universal_variables_variable_foo[1]
if test $__fish_test_universal_variables_variable_foo '=' def
echo Test 11 pass
else
echo Test 11 fail
end
# Test combinations of export and scope
set -ge __fish_test_universal_variables_variable_foo
set -Ue __fish_test_universal_variables_variable_foo
set -Ux __fish_test_universal_variables_variable_foo bar
set __fish_test_universal_variables_variable_foo baz
if test (/bin/sh -c 'echo $__fish_test_universal_variables_variable_foo') = baz -a (../fish -c 'echo $__fish_test_universal_variables_variable_foo') = baz
echo Test 12 pass
else
echo Test 12 fail
end
set -Ue __fish_test_universal_variables_variable_foo
# Should no longer be in environment (#2046)
env | __fish_sgrep __fish_test_universal_variables_variable_foo
set -Ux __fish_test_universal_variables_variable_foo bar
set -U __fish_test_universal_variables_variable_foo baz
if test (/bin/sh -c 'echo $__fish_test_universal_variables_variable_foo') = baz -a (../fish -c 'echo $__fish_test_universal_variables_variable_foo') = baz
echo Test 13 pass
else
echo Test 13 fail
end
set -Ux __fish_test_universal_variables_variable_foo bar
set -u __fish_test_universal_variables_variable_foo bar
if test (/bin/sh -c 'echo $__fish_test_universal_variables_variable_foo') = '' -a (../fish -c 'echo $__fish_test_universal_variables_variable_foo') = bar
echo Test 14 pass
else
echo Test 14 fail
end
set -Ux __fish_test_universal_variables_variable_foo bar
set -Uu __fish_test_universal_variables_variable_foo baz
if test (/bin/sh -c 'echo $__fish_test_universal_variables_variable_foo') = '' -a (../fish -c 'echo $__fish_test_universal_variables_variable_foo') = baz
echo Test 15 pass
else
echo Test 15 fail
end
set -eU __fish_test_universal_variables_variable_foo
function watch_foo --on-variable __fish_test_universal_variables_variable_foo
echo Foo change detected
end
set -U __fish_test_universal_variables_variable_foo 1234
set -eU __fish_test_universal_variables_variable_foo
functions -e watch_foo
# test erasing variables without a specified scope
set -g test16res
set -U __fish_test_universal_variables_variable_foo universal
set -g __fish_test_universal_variables_variable_foo global
begin
set -l __fish_test_universal_variables_variable_foo blocklocal
function test16
set -l __fish_test_universal_variables_variable_foo function
begin
set -l __fish_test_universal_variables_variable_foo functionblock
set test16res $test16res (echo $__fish_test_universal_variables_variable_foo)
set -e __fish_test_universal_variables_variable_foo
set test16res $test16res (echo $__fish_test_universal_variables_variable_foo)
set -e __fish_test_universal_variables_variable_foo
set test16res $test16res (echo $__fish_test_universal_variables_variable_foo)
set -e __fish_test_universal_variables_variable_foo
set test16res $test16res (echo $__fish_test_universal_variables_variable_foo)
set -e __fish_test_universal_variables_variable_foo
set test16res $test16res (echo $__fish_test_universal_variables_variable_foo)
end
set test16res $test16res (echo $__fish_test_universal_variables_variable_foo)
set -e __fish_test_universal_variables_variable_foo
end
test16
set test16res $test16res (echo $__fish_test_universal_variables_variable_foo)
end
set test16res $test16res (echo $__fish_test_universal_variables_variable_food)
#echo count: (count $test16res) "content:[$test16res]"
if test (count $test16res) = 8 -a "$test16res" = "functionblock function global universal blocklocal "
echo Test 16 pass
else
echo Test 16 fail
end
# Test that shadowing with a non-exported variable works
set -gx __fish_test_env17 UNSHADOWED
env | __fish_sgrep __fish_test_env17
function __fish_test_shadow
set -l __fish_test_env17
env | __fish_sgrep __fish_test_env17 ; or echo SHADOWED
end
__fish_test_shadow
# clear for other shells
set -eU __fish_test_universal_variables_variable_foo
# Test behavior of universals on startup (#1526)
echo Testing Universal Startup
set -U testu 0
../fish -c 'set -U testu 1'
echo $testu
../fish -c 'echo $testu'
../fish -c 'set -U testu 2'
echo $testu
../fish -c 'echo $testu'
../fish -c 'set -e testu';
echo Missing: $testu
../fish -c 'echo Missing: $testu'
# test SHLVL
# use a subshell to ensure a clean slate
env SHLVL= ../fish -c 'echo SHLVL: $SHLVL; ../fish -c \'echo SHLVL: $SHLVL\''
# exec should decrement SHLVL
env SHLVL= ../fish -c 'echo SHLVL: $SHLVL; exec ../fish -c \'echo SHLVL: $SHLVL\''
# garbage SHLVLs should be treated as garbage
env SHLVL=3foo ../fish -c 'echo SHLVL: $SHLVL'
# whitespace is allowed though (for bash compatibility)
env SHLVL="3 " ../fish -c 'echo SHLVL: $SHLVL'
env SHLVL=" 3" ../fish -c 'echo SHLVL: $SHLVL'
# Test transformation of inherited variables
env DISPLAY="localhost:0.0" ../fish -c 'echo Elements in DISPLAY: (count $DISPLAY)'
# We can't use PATH for this because the global configuration will modify PATH
# based on /etc/paths and /etc/paths.d.
# Exported arrays should use record separator, with a few exceptions. So we can use an arbitrary variable for this.
env FOO=one\x1etwo\x1ethree\x1efour ../fish -c 'echo Elements in FOO: (count $FOO)'
# some must use colon separators!
set -lx MANPATH man1 man2 man3 ; env | grep MANPATH
true
|