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

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