OILS / spec / builtin-oils.test.sh View on Github | oils.pub

267 lines, 122 significant
1## compare_shells: bash
2## oils_failures_allowed: 3
3
4#### invoke usage
5case $SH in bash) exit ;; esac
6
7invoke
8echo status=$?
9
10invoke --
11echo status=$?
12
13echo
14
15invoke sleep 0
16echo status=$?
17
18invoke -- sleep 0
19echo status=$?
20
21invoke --builtin -- sleep 0
22echo status=$?
23
24## STDOUT:
25status=2
26status=2
27
28status=0
29status=0
30status=0
31## END
32## N-I bash STDOUT:
33## END
34
35#### invoke nonexistent name
36case $SH in bash) exit ;; esac
37
38invoke zz
39echo status=$?
40
41invoke --builtin zz
42echo status=$?
43
44invoke --builtin -- zz
45echo status=$?
46
47## STDOUT:
48status=1
49status=1
50status=1
51## END
52## N-I bash STDOUT:
53## END
54
55#### type and command builtin does not find private sleep, because it's not enabled
56
57# Does Oils have __builtins__.special __builtins__.normal __builtins__.private
58# perhaps? That is another way of introspecting
59
60remove-path() { sed 's;/.*/;;'; }
61
62type -t sleep
63type sleep | remove-path
64echo
65
66command -v sleep | remove-path
67
68## STDOUT:
69file
70sleep is sleep
71
72sleep
73## END
74
75#### type -a does not find private builtins
76
77remove-path() { sed 's;/.*/;;'; }
78
79# this is meant to find the "first word"
80type -a sleep | remove-path | uniq
81
82## STDOUT:
83sleep is sleep
84## END
85
86#### but invoke --show finds the private builtin (alternative to type, command)
87case $SH in bash) exit ;; esac
88
89invoke --show sleep | grep builtin
90
91## stdout-json: "sleep\tbuiltin\tp\n"
92
93## N-I bash STDOUT:
94## END
95
96#### invoke --show with many types
97case $SH in bash) exit ;; esac
98
99my-name() { echo sh-func; }
100
101alias my-name='echo my-alias'
102
103# Why isn't this showing up?
104# manual bug: I get 2 argv?
105
106mkdir -p dir
107echo 'echo hi' > dir/my-name
108chmod +x dir/my-name
109PATH=$PWD/dir:$PATH
110#echo $PATH
111
112command -v my-name
113type -a my-name
114
115shopt --set ysh:all
116
117proc my-name { echo proc }
118
119invoke --show my-name eval cd
120
121## STDOUT:
122## END
123
124## N-I bash STDOUT:
125## END
126
127
128#### invoke --show does proper quoting
129case $SH in bash) exit ;; esac
130
131alias $'bad-alias=echo \xff\necho z'
132
133bad-alias | od -A n -t x1
134
135# The tabs are a bit annoying to work with ...
136# Maybe #.ssv8 instead of #.tsv8 ?
137invoke --show bad-alias
138
139#alias $'bad=hi\xffname=echo hi'
140#$'bad\xffname'
141
142## STDOUT:
143 ff 0a 7a 0a
144bad-alias alias b'echo \yff\necho z'
145## END
146
147## N-I bash STDOUT:
148## END
149
150#### builtin sleep behaves like external sleep
151case $SH in
152 *osh) prefix='builtin' ;;
153 *) prefix='' ;;
154esac
155
156$prefix sleep
157if test "$?" != 0; then
158 echo ok
159fi
160
161# This is different! OSH is stricter
162if false; then
163$prefix sleep --
164if test "$?" != 0; then
165 echo ok
166fi
167fi
168
169$prefix sleep -2
170if test "$?" != 0; then
171 echo ok
172fi
173
174$prefix sleep -- -2
175if test "$?" != 0; then
176 echo ok
177fi
178
179$prefix sleep zz
180if test "$?" != 0; then
181 echo ok
182fi
183
184$prefix sleep 0
185echo status=$?
186
187$prefix sleep -- 0
188echo status=$?
189
190$prefix sleep '0.0005'
191echo status=$?
192
193$prefix sleep '+0.0005'
194echo status=$?
195
196## STDOUT:
197ok
198ok
199ok
200ok
201status=0
202status=0
203status=0
204status=0
205## END
206
207#### builtin sleep usage errors
208case $SH in bash) exit ;; esac
209
210builtin sleep 0.5s
211echo status=$?
212
213builtin sleep 0.1 extra
214echo status=$?
215
216## STDOUT:
217status=2
218status=2
219## END
220## N-I bash STDOUT:
221## END
222
223#### sleep without prefix is still external
224
225# should not work
226builtin sleep --version
227if test "$?" != '0'; then
228 echo ok
229fi
230
231sleep --version | head -n 1 >& 2
232echo status=$?
233
234## STDOUT:
235ok
236status=0
237## END
238
239#### builtin cat
240case $SH in bash) exit ;; esac
241
242seq 3 | builtin cat
243
244## STDOUT:
2451
2462
2473
248## END
249## N-I bash STDOUT:
250## END
251
252
253#### builtin readlink
254case $SH in bash) exit ;; esac
255
256echo TODO
257
258# turn this into a builtin
259# does that mean any builtin can be externalized?
260# - [ aka test is a good candiate
261# - we have stubs from true/false
262
263## STDOUT:
264## END
265
266## N-I bash STDOUT:
267## END