OILS / spec / fatal-errors.test.sh View on Github | oilshell.org

186 lines, 60 significant
1#
2# Some shell errors are unrecoverable! Like divide by zero (except in bash.
3#
4# Any others?
5
6
7#### Unrecoverable: divide by zero in redirect word
8
9$SH -c '
10echo hi > file$(( 42 / 0 )) in
11echo inside=$?
12'
13echo outside=$?
14
15## STDOUT:
16outside=1
17## END
18
19## OK dash/ash STDOUT:
20outside=2
21## END
22
23# bash makes the command fail
24## OK bash STDOUT:
25inside=1
26outside=0
27## END:
28
29
30#### Unrecoverable: divide by zero in conditional word
31
32$SH -c '
33if test foo$(( 42 / 0 )) = foo; then
34 echo true
35else
36 echo false
37fi
38echo inside=$?
39'
40echo outside=$?
41
42echo ---
43
44$SH -c '
45if test foo$(( 42 / 0 )) = foo; then
46 echo true
47fi
48echo inside=$?
49'
50echo outside=$?
51
52## STDOUT:
53outside=1
54---
55outside=1
56## END
57
58## OK dash/ash STDOUT:
59outside=2
60---
61outside=2
62## END
63
64# bash makes the command fail
65## OK bash STDOUT:
66inside=1
67outside=0
68---
69inside=1
70outside=0
71## END:
72
73# weird difference in zsh!
74
75## BUG zsh STDOUT:
76outside=1
77---
78outside=0
79## END
80
81
82#### Unrecoverable: divide by zero in case
83
84$SH -c '
85case $(( 42 / 0 )) in
86 (*) echo hi ;;
87esac
88echo inside=$?
89'
90echo outside=$?
91
92echo ---
93
94$SH -c '
95case foo in
96 ( $(( 42 / 0 )) )
97 echo hi
98 ;;
99esac
100echo inside=$?
101'
102echo outside=$?
103
104## STDOUT:
105outside=1
106---
107outside=1
108## END
109
110## OK dash/ash STDOUT:
111outside=2
112---
113outside=2
114## END
115
116## OK bash STDOUT:
117inside=1
118outside=0
119---
120inside=1
121outside=0
122## END:
123
124## BUG zsh STDOUT:
125outside=0
126---
127outside=0
128## END
129
130
131#### Unrecoverable: ${undef?message}
132
133$SH -c '
134echo ${undef?message}
135echo inside=$?
136'
137echo outside=$?
138
139$SH -c '
140case ${undef?message} in
141 (*) echo hi ;;
142esac
143echo inside=$?
144'
145echo outside=$?
146
147## STDOUT:
148outside=1
149outside=1
150## END
151## OK dash STDOUT:
152outside=2
153outside=2
154## END
155## OK bash STDOUT:
156outside=127
157outside=127
158## END
159
160#### ${undef} with nounset
161
162$SH -c '
163set -o nounset
164case ${undef} in
165 (*) echo hi ;;
166esac
167echo inside=$?
168'
169echo outside=$?
170
171## STDOUT:
172outside=1
173## END
174
175## OK dash STDOUT:
176outside=2
177## END
178
179## OK bash STDOUT:
180outside=127
181## END
182
183## BUG zsh STDOUT:
184outside=0
185## END
186