OILS / spec / toysh-posix.test.sh View on Github | oilshell.org

344 lines, 148 significant
1## oils_failures_allowed: 3
2## compare_shells: bash dash mksh zsh yash
3
4#### Fatal error
5# http://landley.net/notes.html#20-06-2020
6
7abc=${a?bc} echo hello; echo blah
8## status: 1
9## OK yash/dash status: 2
10## stdout-json: ""
11
12#### setting readonly var (bash is only one where it's non-fatal)
13# http://landley.net/notes.html#20-06-2020
14
15readonly abc=123
16abc=def
17echo status=$?
18## status: 2
19## stdout-json: ""
20## OK osh/zsh status: 1
21## OK bash status: 0
22## BUG bash STDOUT:
23status=1
24## END
25
26#### readonly with temp binding
27# http://landley.net/notes.html#20-06-2020
28
29# temp binding
30readonly abc=123
31abc=def echo one
32echo status=$?
33
34echo potato < /does/not/exist || echo hello
35
36## status: 2
37## stdout-json: ""
38## OK osh/bash status: 0
39## OK osh/bash STDOUT:
40one
41status=0
42hello
43## END
44## OK zsh status: 1
45
46#### Failed redirect in assignment, vs. export
47
48abc=def > /does/not/exist1
49echo abc=$abc
50
51export abc=def > /does/not/exist2
52echo abc=$abc
53
54## STDOUT:
55abc=
56abc=
57## END
58## BUG bash STDOUT:
59abc=def
60abc=def
61## END
62## OK dash/mksh STDOUT:
63abc=
64## END
65## OK dash status: 2
66## OK mksh status: 1
67
68#### Evaluation order of redirect and ${undef?error}
69# http://landley.net/notes.html#12-06-2020
70rm *
71
72rm -f walrus
73$SH -c 'X=${x?bc} > walrus'
74if test -f walrus; then echo 'exists1'; fi
75
76rm -f walrus
77$SH -c '>walrus echo ${a?bc}'
78test -f walrus
79if test -f walrus; then echo 'exists2'; fi
80## STDOUT:
81exists1
82## END
83## OK bash stdout-json: ""
84
85#### Function def in pipeline
86# http://landley.net/notes.html#26-05-2020
87
88echo hello | potato() { echo abc; } | echo ha
89
90## STDOUT:
91ha
92## END
93
94#### dynamic glob - http://landley.net/notes.html#08-05-2020
95rm * # setup
96X='*'; echo $X
97echo "*"*".?z"
98## STDOUT:
99_tmp
100**.?z
101## END
102## BUG zsh status: 1
103## BUG zsh STDOUT:
104*
105## END
106
107#### no shebang
108rm *
109
110cat > snork << 'EOF'
111echo hello $BLAH
112EOF
113
114chmod +x snork
115$SH -c 'BLAH=123; ./snork'
116$SH -c 'BLAH=123; exec ./snork'
117$SH -c 'BLAH=123 exec ./snork'
118## STDOUT:
119hello
120hello
121hello 123
122## END
123
124
125#### IFS
126
127IFS=x; X=abxcd; echo ${X/bxc/g}
128
129X=a=\"\$a\"; echo ${X//a/{x,y,z}}
130
131## STDOUT:
132agd
133{ ,y,z="${ ,y,z"}
134## END
135## BUG zsh STDOUT:
136agd
137{x,y,z}="${x,y,z}"
138## END
139## N-I dash status: 2
140## N-I dash stdout-json: ""
141
142#### shift is fatal at top level?
143# http://landley.net/notes.html#08-04-2020
144
145# This makes a difference for zsh, but not for bash?
146#set -o posix
147
148$SH -c 'shift; echo hello'
149## STDOUT:
150hello
151## END
152## OK dash status: 2
153## OK mksh status: 1
154## OK dash/mksh stdout-json: ""
155
156#### var and func - http://landley.net/notes.html#19-03-2020
157potato() { echo hello; }
158potato=42
159echo $potato
160
161potato
162
163## STDOUT:
16442
165hello
166## END
167
168
169#### IFS - http://landley.net/notes.html#05-03-2020
170
171IFS=x
172chicken() { for i in "$@"; do echo =$i=; done;}
173chicken one abc dxf ghi
174
175echo ---
176myfunc() { "$SH" -c 'IFS=x; for i in $@; do echo =$i=; done' blah "$@"; }
177myfunc one "" two
178
179## STDOUT:
180=one=
181=abc=
182=d f=
183=ghi=
184---
185=one=
186==
187=two=
188## END
189## BUG dash STDOUT:
190=one=
191=abc=
192=d f=
193=ghi=
194---
195=one=
196=two=
197## END
198## BUG zsh status: 1
199## BUG zsh stdout-json: ""
200
201#### for loop parsing - http://landley.net/notes.html#04-03-2020
202
203$SH -c '
204for i
205in one two three
206do echo $i;
207done
208'
209echo $?
210
211$SH -c 'for i; in one two three; do echo $i; done'
212test $? -ne 0 && echo cannot-parse
213
214## STDOUT:
215one
216two
217three
2180
219cannot-parse
220## END
221
222#### Parsing $(( ))
223# http://landley.net/notes.html#15-03-2020
224$SH -c 'echo $((echo hello))'
225if test $? -ne 0; then echo fail; fi
226## stdout: fail
227
228#### IFS - http://landley.net/notes.html#15-02-2020 (TODO: osh)
229
230IFS=x; A=xabcxx; for i in $A; do echo =$i=; done
231
232unset IFS; A=" abc def "; for i in ""$A""; do echo =$i=; done
233
234## STDOUT:
235==
236=abc=
237==
238==
239=abc=
240=def=
241==
242## END
243## BUG zsh status: 1
244## BUG zsh stdout-json: ""
245
246#### IFS 2 (TODO: osh)
247this one appears different between osh and bash
248A=" abc def "; for i in ""x""$A""; do echo =$i=; done
249
250## STDOUT:
251=x=
252=abc=
253=def=
254==
255## END
256## BUG zsh status: 1
257## BUG zsh stdout-json: ""
258
259#### IFS 3
260IFS=x; X="onextwoxxthree"; y=$X; echo $y
261## STDOUT:
262one two three
263## END
264## BUG zsh STDOUT:
265onextwoxxthree
266## END
267
268#### IFS 4
269IFS=x
270cc() { echo =$*=; for i in $*; do echo -$i-; done;}; cc "" ""
271cc() { echo ="$*"=; for i in =$*=; do echo -$i-; done;}; cc "" ""
272## STDOUT:
273= =
274--
275=x=
276-=-
277-=-
278## END
279## BUG mksh/dash STDOUT:
280= =
281=x=
282-=-
283-=-
284## END
285## BUG yash STDOUT:
286= =
287--
288--
289=x=
290-=-
291-=-
292## END
293## BUG zsh STDOUT:
294= =
295## END
296## BUG zsh status: 1
297
298#### IFS 5
299cc() { for i in $*; do echo -$i-; done;}; cc "" "" "" "" ""
300cc() { echo =$1$2=;}; cc "" ""
301## STDOUT:
302==
303## END
304## BUG yash STDOUT:
305--
306--
307--
308--
309--
310==
311## END
312## BUG zsh status: 1
313## BUG zsh stdout-json: ""
314
315#### Can't parse extra }
316
317$SH -c 'for i in a"$@"b;do echo =$i=;done;}' 123 456 789
318## status: 2
319## OK mksh/zsh status: 1
320## STDOUT:
321## END
322
323#### Command Sub Syntax Error
324# http://landley.net/notes.html#28-01-2020
325
326echo $(if true)
327echo $?
328echo $(false)
329echo $?
330
331## status: 2
332## stdout-json: ""
333
334## OK mksh/zsh status: 1
335
336
337#### Pipeline - http://landley.net/notes-2019.html#16-12-2019
338echo hello | { read i; echo $i;} | { read i; echo $i;} | cat
339echo hello | while read i; do echo -=$i=- | sed s/=/@/g ; done | cat
340## STDOUT:
341hello
342-@hello@-
343## END
344