blob: e159468344c6b99ad8622448dad029c8fb69d838 (
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
|
# 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 foo
set -g foo bar
begin
set -l foo baz
set -eg foo
end
if set -q foo
echo Test 10 fail
else
echo Test 10 pass
end
set foo abc def
set -e foo[1]
if test $foo '=' def
echo Test 11 pass
else
echo Test 11 fail
end
|