OILS / spec / bugs.test.sh View on Github | oilshell.org

362 lines, 141 significant
1
2## compare_shells: bash dash mksh zsh ash
3## oils_failures_allowed: 0
4
5#### echo keyword
6echo done
7## stdout: done
8
9#### if/else
10if false; then
11 echo THEN
12else
13 echo ELSE
14fi
15## stdout: ELSE
16
17#### Turn an array into an integer.
18a=(1 2 3)
19(( a = 42 ))
20echo $a
21## stdout: 42
22## N-I dash/ash stdout-json: ""
23## N-I dash/ash status: 2
24
25
26#### assign readonly -- one line
27readonly x=1; x=2; echo hi
28## status: 1
29## OK dash/mksh/ash status: 2
30## STDOUT:
31## END
32
33#### assign readonly -- multiple lines
34readonly x=1
35x=2
36echo hi
37## status: 1
38## OK dash/mksh/ash status: 2
39## STDOUT:
40## END
41## BUG bash status: 0
42## BUG bash STDOUT:
43hi
44## END
45
46#### assign readonly -- multiple lines -- set -o posix
47set -o posix
48readonly x=1
49x=2
50echo hi
51## status: 1
52## OK dash/mksh/ash status: 2
53## STDOUT:
54## END
55
56#### unset readonly -- one line
57readonly x=1; unset x; echo hi
58## STDOUT:
59hi
60## END
61## OK dash/ash status: 2
62## OK zsh status: 1
63## OK dash/ash stdout-json: ""
64## OK zsh stdout-json: ""
65
66#### unset readonly -- multiple lines
67readonly x=1
68unset x
69echo hi
70## OK dash/ash status: 2
71## OK zsh status: 1
72## OK dash/ash stdout-json: ""
73## OK zsh stdout-json: ""
74
75#### First word like foo$x() and foo$[1+2] (regression)
76
77# Problem: $x() func call broke this error message
78foo$identity('z')
79
80foo$[1+2]
81
82echo DONE
83
84## status: 2
85## OK mksh/zsh status: 1
86## STDOUT:
87## END
88
89#### Function names
90foo$x() {
91 echo hi
92}
93
94foo $x() {
95 echo hi
96}
97
98## status: 2
99## OK mksh/zsh status: 1
100## BUG zsh status: 0
101## STDOUT:
102## END
103
104
105#### file with NUL byte
106echo -e 'echo one \0 echo two' > tmp.sh
107$SH tmp.sh
108## STDOUT:
109one echo two
110## END
111## OK osh STDOUT:
112one
113## END
114## N-I dash stdout-json: ""
115## N-I dash status: 127
116## OK bash stdout-json: ""
117## OK bash status: 126
118## OK zsh stdout-json: "one \u0000echo two\n"
119
120#### fastlex: PS1 format string that's incomplete / with NUL byte
121case $SH in bash) exit ;; esac
122
123x=$'\\D{%H:%M' # leave off trailing }
124echo x=${x@P}
125
126## STDOUT:
127x=\D{%H:%M
128## END
129
130# bash just ignores the missing }
131## BUG bash stdout-json: ""
132
133# These shells don't understand @P
134
135## N-I dash/ash stdout-json: ""
136## N-I dash/ash status: 2
137
138## N-I zsh stdout-json: ""
139## N-I zsh status: 1
140
141
142#### 'echo' and printf fail on writing to full disk
143
144# Inspired by https://blog.sunfishcode.online/bugs-in-hello-world/
145
146echo hi > /dev/full
147echo status=$?
148
149printf '%s\n' hi > /dev/full
150echo status=$?
151
152## STDOUT:
153status=1
154status=1
155## END
156
157#### other builtins fail on writing to full disk
158
159type echo > /dev/full
160echo status=$?
161
162# other random builtin
163ulimit -a > /dev/full
164echo status=$?
165
166## STDOUT:
167status=1
168status=1
169## END
170
171## BUG mksh/zsh STDOUT:
172status=0
173status=0
174## END
175
176#### subshell while running a script (regression)
177# Ensures that spawning a subshell doesn't cause a seek on the file input stream
178# representing the current script (issue #1233).
179cat >tmp.sh <<'EOF'
180echo start
181(:)
182echo end
183EOF
184$SH tmp.sh
185## STDOUT:
186start
187end
188## END
189
190#### for loop (issue #1446)
191case $SH in (dash|mksh|ash) exit ;; esac
192
193for (( n=0; n<(3-(1)); n++ )) ; do echo $n; done
194
195## STDOUT:
1960
1971
198## END
199## N-I dash/mksh/ash STDOUT:
200## END
201
202
203
204#### for loop 2 (issue #1446)
205case $SH in (dash|mksh|ash) exit ;; esac
206
207
208for (( n=0; n<(3- (1)); n++ )) ; do echo $n; done
209
210## STDOUT:
2110
2121
213## END
214## N-I dash/mksh/ash STDOUT:
215## END
216
217#### autoconf word split (#1449)
218
219mysed() {
220 for line in "$@"; do
221 echo "[$line]"
222 done
223}
224
225sedinputs="f1 f2"
226sedscript='my sed command'
227
228# Parsed and evaluated correctly: with word_part.EscapedLiteral \"
229
230x=$(eval "mysed -n \"\$sedscript\" $sedinputs")
231echo '--- $()'
232echo "$x"
233
234# With backticks, the \" gets lost somehow
235
236x=`eval "mysed -n \"\$sedscript\" $sedinputs"`
237echo '--- backticks'
238echo "$x"
239
240
241# Test it in a case statement
242
243case `eval "mysed -n \"\$sedscript\" $sedinputs"` in
244 (*'[my sed command]'*)
245 echo 'NOT SPLIT'
246 ;;
247esac
248
249## STDOUT:
250--- $()
251[-n]
252[my sed command]
253[f1]
254[f2]
255--- backticks
256[-n]
257[my sed command]
258[f1]
259[f2]
260NOT SPLIT
261## END
262
263#### autoconf arithmetic - relaxed eval_unsafe_arith (#1450)
264
265as_fn_arith ()
266{
267 as_val=$(( $* ))
268}
269as_fn_arith 1 + 1
270echo $as_val
271
272## STDOUT:
2732
274## END
275
276#### command execution $(echo 42 | tee PWNED) not allowed
277
278rm -f PWNED
279
280x='a[$(echo 42 | tee PWNED)]=1'
281echo $(( x ))
282
283if test -f PWNED; then
284 cat PWNED
285else
286 echo NOPE
287fi
288
289## status: 1
290## OK dash/ash status: 2
291## stdout-json: ""
292## BUG bash/mksh/zsh status: 0
293## BUG bash/mksh/zsh STDOUT:
2941
29542
296## END
297
298#### process sub <(echo 42 | tee PWNED) not allowed
299
300rm -f PWNED
301
302x='a[<(echo 42 | tee PWNED)]=1'
303echo $(( x ))
304
305if test -f PWNED; then
306 cat PWNED
307else
308 echo NOPE
309fi
310
311## status: 1
312## stdout-json: ""
313
314## OK dash/ash status: 2
315
316# bash keeps going
317## BUG bash status: 0
318## BUG bash STDOUT:
319NOPE
320## END
321
322
323#### unset doesn't allow command execution
324
325typeset -a a # for mksh
326a=(42)
327echo len=${#a[@]}
328
329unset -v 'a[$(echo 0 | tee PWNED)]'
330echo len=${#a[@]}
331
332if test -f PWNED; then
333 echo PWNED
334 cat PWNED
335else
336 echo NOPE
337fi
338
339## status: 1
340## STDOUT:
341len=1
342## END
343
344## N-I dash/ash status: 2
345## N-I dash/ash stdout-json: ""
346
347## BUG bash/mksh status: 0
348## BUG bash/mksh STDOUT:
349len=1
350len=0
351PWNED
3520
353## END
354
355## BUG zsh status: 0
356## BUG zsh STDOUT:
357len=1
358len=1
359PWNED
3600
361## END
362