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

342 lines, 133 significant
1
2## compare_shells: bash dash mksh zsh ash
3## oils_failures_allowed: 1
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 to disk full
143
144# Inspired by https://blog.sunfishcode.online/bugs-in-hello-world/
145
146echo hi > /dev/full
147echo status=$?
148printf '%s\n' hi > /dev/full
149echo status=$?
150
151## STDOUT:
152status=1
153status=1
154## END
155
156#### subshell while running a script (regression)
157# Ensures that spawning a subshell doesn't cause a seek on the file input stream
158# representing the current script (issue #1233).
159cat >tmp.sh <<'EOF'
160echo start
161(:)
162echo end
163EOF
164$SH tmp.sh
165## STDOUT:
166start
167end
168## END
169
170#### for loop (issue #1446)
171case $SH in (dash|mksh|ash) exit ;; esac
172
173for (( n=0; n<(3-(1)); n++ )) ; do echo $n; done
174
175## STDOUT:
1760
1771
178## END
179## N-I dash/mksh/ash STDOUT:
180## END
181
182
183
184#### for loop 2 (issue #1446)
185case $SH in (dash|mksh|ash) exit ;; esac
186
187
188for (( n=0; n<(3- (1)); n++ )) ; do echo $n; done
189
190## STDOUT:
1910
1921
193## END
194## N-I dash/mksh/ash STDOUT:
195## END
196
197#### autoconf word split (#1449)
198
199mysed() {
200 for line in "$@"; do
201 echo "[$line]"
202 done
203}
204
205sedinputs="f1 f2"
206sedscript='my sed command'
207
208# Parsed and evaluated correctly: with word_part.EscapedLiteral \"
209
210x=$(eval "mysed -n \"\$sedscript\" $sedinputs")
211echo '--- $()'
212echo "$x"
213
214# With backticks, the \" gets lost somehow
215
216x=`eval "mysed -n \"\$sedscript\" $sedinputs"`
217echo '--- backticks'
218echo "$x"
219
220
221# Test it in a case statement
222
223case `eval "mysed -n \"\$sedscript\" $sedinputs"` in
224 (*'[my sed command]'*)
225 echo 'NOT SPLIT'
226 ;;
227esac
228
229## STDOUT:
230--- $()
231[-n]
232[my sed command]
233[f1]
234[f2]
235--- backticks
236[-n]
237[my sed command]
238[f1]
239[f2]
240NOT SPLIT
241## END
242
243#### autoconf arithmetic - relaxed eval_unsafe_arith (#1450)
244
245as_fn_arith ()
246{
247 as_val=$(( $* ))
248}
249as_fn_arith 1 + 1
250echo $as_val
251
252## STDOUT:
2532
254## END
255
256#### command execution $(echo 42 | tee PWNED) not allowed
257
258rm -f PWNED
259
260x='a[$(echo 42 | tee PWNED)]=1'
261echo $(( x ))
262
263if test -f PWNED; then
264 cat PWNED
265else
266 echo NOPE
267fi
268
269## status: 1
270## OK dash/ash status: 2
271## stdout-json: ""
272## BUG bash/mksh/zsh status: 0
273## BUG bash/mksh/zsh STDOUT:
2741
27542
276## END
277
278#### process sub <(echo 42 | tee PWNED) not allowed
279
280rm -f PWNED
281
282x='a[<(echo 42 | tee PWNED)]=1'
283echo $(( x ))
284
285if test -f PWNED; then
286 cat PWNED
287else
288 echo NOPE
289fi
290
291## status: 1
292## stdout-json: ""
293
294## OK dash/ash status: 2
295
296# bash keeps going
297## BUG bash status: 0
298## BUG bash STDOUT:
299NOPE
300## END
301
302
303#### unset doesn't allow command execution
304
305typeset -a a # for mksh
306a=(42)
307echo len=${#a[@]}
308
309unset -v 'a[$(echo 0 | tee PWNED)]'
310echo len=${#a[@]}
311
312if test -f PWNED; then
313 echo PWNED
314 cat PWNED
315else
316 echo NOPE
317fi
318
319## status: 1
320## STDOUT:
321len=1
322## END
323
324## N-I dash/ash status: 2
325## N-I dash/ash stdout-json: ""
326
327## BUG bash/mksh status: 0
328## BUG bash/mksh STDOUT:
329len=1
330len=0
331PWNED
3320
333## END
334
335## BUG zsh status: 0
336## BUG zsh STDOUT:
337len=1
338len=1
339PWNED
3400
341## END
342