-
Notifications
You must be signed in to change notification settings - Fork 28
/
command-p.tst
291 lines (237 loc) · 4.87 KB
/
command-p.tst
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# command-p.tst: test of the command built-in for any POSIX-compliant shell
posix="true"
test_o 'redirection error on special built-in does not kill shell'
command : <_no_such_file_
echo reached
__IN__
reached
__OUT__
test_o 'dot script not found does not kill shell'
command . ./_no_such_file_
echo reached
__IN__
reached
__OUT__
test_o 'assignment on special built-in is temporary'
a=a
a=b command :
echo $a
__IN__
a
__OUT__
test_OE -e n 'command ignores function (mandatory built-in)'
false () { true; }
command false
__IN__
test_E -e 0 'command ignores function (substitutive built-in)'
echo () { false; }
command echo
__IN__
test_OE -e 0 'command ignores function (external command)'
cat () { false; }
command cat </dev/null
__IN__
test_oE -e 0 'command exec retains redirection'
command exec 3<<\__END__
here
__END__
cat <&3
__IN__
here
__OUT__
test_oE 'effect on environment'
command read a <<\__END__
foo
__END__
echo $a
__IN__
foo
__OUT__
test_o -e 0 'executing with standard path'
PATH=
command -p echo foo bar | command -p cat
__IN__
foo bar
__OUT__
(
setup 'set -e'
test_oE -e 0 'describing reserved word ! (-v)'
command -v !
__IN__
!
__OUT__
test_oE -e 0 'describing reserved word { (-v)'
command -v {
__IN__
{
__OUT__
test_oE -e 0 'describing reserved word } (-v)'
command -v }
__IN__
}
__OUT__
test_oE -e 0 'describing reserved word case (-v)'
command -v case
__IN__
case
__OUT__
test_oE -e 0 'describing reserved word do (-v)'
command -v do
__IN__
do
__OUT__
test_oE -e 0 'describing reserved word done (-v)'
command -v done
__IN__
done
__OUT__
test_oE -e 0 'describing reserved word elif (-v)'
command -v elif
__IN__
elif
__OUT__
test_oE -e 0 'describing reserved word else (-v)'
command -v else
__IN__
else
__OUT__
test_oE -e 0 'describing reserved word esac (-v)'
command -v esac
__IN__
esac
__OUT__
test_oE -e 0 'describing reserved word fi (-v)'
command -v fi
__IN__
fi
__OUT__
test_oE -e 0 'describing reserved word for (-v)'
command -v for
__IN__
for
__OUT__
test_oE -e 0 'describing reserved word if (-v)'
command -v if
__IN__
if
__OUT__
test_oE -e 0 'describing reserved word in (-v)'
command -v in
__IN__
in
__OUT__
test_oE -e 0 'describing reserved word then (-v)'
command -v then
__IN__
then
__OUT__
test_oE -e 0 'describing reserved word until (-v)'
command -v until
__IN__
until
__OUT__
test_oE -e 0 'describing reserved word while (-v)'
command -v while
__IN__
while
__OUT__
test_E -e 0 'describing reserved word (-V)'
command -V !
__IN__
test_oE -e 0 'describing special built-in (-v)'
command -v :
__IN__
:
__OUT__
test_E -e 0 'describing special built-in (-V)'
command -V :
__IN__
test_x -e 0 'exit status of describing non-special built-in (-v)'
command -v echo
__IN__
test_x -e 0 'exit status of describing non-special built-in (-V)'
command -V echo
__IN__
test_E -e 0 'output of describing non-special built-in (-v)'
command -v echo | grep '^/'
__IN__
test_x -e 0 'output of describing non-special built-in (-V)'
command -V echo | grep -F "$(command -v echo)"
__IN__
test_x -e 0 'exit status of describing external command (-v, no slash)'
command -v cat
__IN__
test_x -e 0 'exit status of describing external command (-V, no slash)'
command -V cat
__IN__
test_E -e 0 'output of describing external command (-v, no slash)'
command -v cat | grep '^/'
__IN__
test_E -e 0 'output of describing external command (-V, no slash)'
command -V cat | grep -F "$(command -v cat)"
__IN__
>foo
chmod a+x foo
test_x -e 0 'exit status of describing external command (-v, with slash)'
command -v ./foo
__IN__
test_x -e 0 'exit status of describing external command (-V, with slash)'
command -V ./foo
__IN__
test_E -e 0 'output of describing external command (-v, with slash)'
command -v ./foo | grep '^/' | grep '/foo$'
__IN__
test_E -e 0 'output of describing external command (-V, with slash)'
command -V ./foo | grep -F "$(command -v ./foo)"
__IN__
test_oE -e 0 'describing function (-v)'
cat() { :; }
command -v cat
__IN__
cat
__OUT__
test_E -e 0 'describing function (-V)'
cat() { :; }
command -V cat
__IN__
test_oE -e 0 'describing alias (-v)'
alias abc='echo ABC'
command="$(command -v abc)"
unalias abc
eval "$command"
abc
__IN__
ABC
__OUT__
test_OE -e 0 'describing alias (-V)'
alias abc=xyz
d="$(command -V abc)"
case "$d" in
(*abc*xyz*|*xyz*abc*) # expected output contains alias name and value
;;
(*)
printf '%s\n' "$d" # print non-conforming result
;;
esac
__IN__
test_OE -e n 'describing non-existent command (-v)'
PATH=
command -v _no_such_command_
__IN__
test_x -e n 'describing non-existent command (-V)'
PATH=
command -V _no_such_command_
__IN__
test_x -e 0 'describing external command with standard path (-v)'
PATH=
command -pv cat
__IN__
test_x -e 0 'describing external command with standard path (-V)'
PATH=
command -pV cat
__IN__
)
test_O -d -e 127 'executing non-existent command'
command ./_no_such_command_
__IN__
# vim: set ft=sh ts=8 sts=4 sw=4 et: