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

231 lines, 112 significant
1## compare_shells: bash
2## oils_failures_allowed: 1
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, but invoke --show does
76case $SH in bash) exit ;; esac
77
78remove-path() { sed 's;/.*/;;'; }
79
80# this is meant to find the "first word"
81type -a sleep | remove-path | uniq
82echo ---
83
84# this also shows private builtins, which are not the first word
85invoke --show sleep | remove-path | uniq
86
87## STDOUT:
88sleep is sleep
89---
90sleep is sleep
91sleep is a private shell builtin
92## END
93
94## N-I bash STDOUT:
95## END
96
97#### but invoke --show finds the private builtin (alternative to type, command)
98case $SH in bash) exit ;; esac
99
100invoke --show sleep | grep private
101
102## STDOUT:
103sleep is a private shell builtin
104## END
105
106## N-I bash STDOUT:
107## END
108
109#### builtin sleep behaves like external sleep
110case $SH in
111 *osh) prefix='builtin' ;;
112 *) prefix='' ;;
113esac
114
115$prefix sleep
116if test "$?" != 0; then
117 echo ok
118fi
119
120# This is different! OSH is stricter
121if false; then
122$prefix sleep --
123if test "$?" != 0; then
124 echo ok
125fi
126fi
127
128$prefix sleep -2
129if test "$?" != 0; then
130 echo ok
131fi
132
133$prefix sleep -- -2
134if test "$?" != 0; then
135 echo ok
136fi
137
138$prefix sleep zz
139if test "$?" != 0; then
140 echo ok
141fi
142
143$prefix sleep 0
144echo status=$?
145
146$prefix sleep -- 0
147echo status=$?
148
149$prefix sleep '0.0005'
150echo status=$?
151
152$prefix sleep '+0.0005'
153echo status=$?
154
155## STDOUT:
156ok
157ok
158ok
159ok
160status=0
161status=0
162status=0
163status=0
164## END
165
166#### builtin sleep usage errors
167case $SH in bash) exit ;; esac
168
169builtin sleep 0.5s
170echo status=$?
171
172builtin sleep 0.1 extra
173echo status=$?
174
175## STDOUT:
176status=2
177status=2
178## END
179## N-I bash STDOUT:
180## END
181
182#### sleep is still external
183
184# should not work
185builtin sleep --version
186if test "$?" != '0'; then
187 echo ok
188fi
189
190sleep --version | head -n 1 >& 2
191echo status=$?
192
193## STDOUT:
194ok
195status=0
196## END
197
198#### cat
199case $SH in bash) exit ;; esac
200
201enable --internal cat
202
203# invoke --internal cat
204# invoke -i cat
205
206seq 3 | __cat
207
208## STDOUT:
2091
2102
2113
212## END
213## N-I bash STDOUT:
214## END
215
216
217#### readlink
218case $SH in bash) exit ;; esac
219
220echo TODO
221
222# turn this into a builtin
223# does that mean any builtin can be externalized?
224# - [ aka test is a good candiate
225# - we have stubs from true/false
226
227## STDOUT:
228## END
229
230## N-I bash STDOUT:
231## END