aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/test4.in
blob: 6d501455320ac0aa98df713269b1c0767878e1fa (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
#Test scoping rules for functions

set -e smurf

function setter
set smurf green
end

function unsetter
set -e smurf
end

function call1
set smurf blue; setter; if test $smurf = blue; echo Test 1 pass; else; echo Test 1 fail; end
end

function call2
set smurf blue; unsetter; if test $smurf = blue; echo Test 2 pass; else; echo Test 2 fail; end
end

call1
call2

function call3
setter; if test $smurf = green; echo Test 3 pass; else; echo Test 3 fail; end
end

function call4
unsetter; if not set -q smurf; echo Test 4 pass; else; echo Test 4 fail; end
end

set -g smurf yellow
call3
call4

set -l foo 1 
set -g bar 2 
set -U baz 3 

set -l -q foo 

if test $status -ne 0
    echo Test 5 fail 
else
    echo Test 5 pass
end;

if not set -g -q bar 
    echo Test 6 fail 
else
    echo Test 6 pass
end;

if not set -U -q baz 
    echo Test 7 fail 
else
    echo Test 7 pass
end;

set -u -l -q foo 
if test $status -ne 0 
    echo Test 8 fail 
else
    echo Test 8 pass

end;

if not set -u -g -q bar 
    echo Test 9 fail 
else
    echo Test 9 pass
end;

if not set -u -U -q baz 
    echo Test 10 fail 
else
    echo Test 10 pass
end;

set -x -l -q foo 
if test $status -eq 0
    echo Test 11 fail 
else
    echo Test 11 pass
end;

if set -x -g -q bar 
    echo Test 12 fail 
else
    echo Test 12 pass
end;

if set -x -U -q baz 
    echo Test 13 fail 
else
    echo Test 13 pass
end;

set -x -l foo 1
set -x -g bar 2
set -x -U baz 3

set -l -q foo 
if test $status -ne 0 
    echo Test 14 fail 
else
    echo Test 14 pass
end;

if not set -g -q bar 
    echo Test 15 fail 
else
    echo Test 15 pass
end;

if not set -U -q baz 
    echo Test 16 fail 
else
    echo Test 16 pass

end;

set -u -l -q foo 
if test $status -ne 1 
    echo Test 17 fail 
else
    echo Test 17 pass
end;

if set -u -g -q bar 
    echo Test 18 fail 
else
    echo Test 18 pass
end;

if set -u -U -q baz 
    echo Test 19 fail 
else
    echo Test 19 pass

end;

set -x -l -q foo 
if test $status -ne 0 
    echo Test 20 fail 
else
    echo Test 20 pass
end;

if not set -x -g -q bar 
    echo Test 21 fail 
else
    echo Test 21 pass
end;

if not set -x -U -q baz 
    echo Test 22 fail 
else
    echo Test 22 pass
end;

set -U -e baz

echo "Verify subcommand statuses"
echo (false) $status (true) $status (false) $status

echo "Verify that set passes through exit status, except when passed -n or -q or -e"
false ; set foo bar ; echo 1 $status # passthrough
true ; set foo bar ; echo 2 $status # passthrough
false ; set -q foo ; echo 3 $status # no passthrough
true ; set -q foo ; echo 4 $status  # no passthrough
false ; set -n > /dev/null ; echo 5 $status # no passthrough
false ; set -e foo ; echo 6 $status # no passthrough
true ; set -e foo ; echo 7 $status # no passthrough
false ; set -h > /dev/null ; echo 8 $status # no passthrough
true ; set -NOT_AN_OPTION 2> /dev/null ; echo 9 $status # no passthrough
false ; set foo (echo A; true) ; echo 10 $status $foo
true ; set foo (echo B; false) ; echo 11 $status $foo
true

echo "Verify set -ql behavior" # see 2502
function setql_check
  set -l setql_foo val
  if set -ql setql_foo
    echo Pass
  else
    echo Fail
  end
end
setql_check