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

226 lines, 78 significant
1## oils_failures_allowed: 3
2## compare_shells: bash dash mksh
3
4#### Long Token - 65535 bytes
5
6python2 -c 'print("echo -n %s" % ("x" * 65535))' > tmp.sh
7$SH tmp.sh > out
8wc --bytes out
9
10## STDOUT:
1165535 out
12## END
13
14#### Token that's too long for Oils - 65536 bytes
15
16python2 -c 'print("echo -n %s" % ("x" * 65536))' > tmp.sh
17$SH tmp.sh > out
18echo status=$?
19wc --bytes out
20
21## STDOUT:
22status=2
230 out
24## END
25
26## OK dash/bash/mksh status: 0
27## OK dash/bash/mksh STDOUT:
28status=0
2965536 out
30## END
31
32#### $% is not a parse error
33echo $%
34## stdout: $%
35
36#### Bad braced var sub -- not allowed
37echo ${%}
38## status: 2
39## OK bash/mksh status: 1
40
41#### Bad var sub caught at parse time
42if test -f /; then
43 echo ${%}
44else
45 echo ok
46fi
47## status: 2
48## BUG dash/bash/mksh status: 0
49
50#### Incomplete while
51echo hi; while
52echo status=$?
53## status: 2
54## stdout-json: ""
55## OK mksh status: 1
56
57#### Incomplete for
58echo hi; for
59echo status=$?
60## status: 2
61## stdout-json: ""
62## OK mksh status: 1
63
64#### Incomplete if
65echo hi; if
66echo status=$?
67## status: 2
68## stdout-json: ""
69## OK mksh status: 1
70
71#### do unexpected
72do echo hi
73## status: 2
74## stdout-json: ""
75## OK mksh status: 1
76
77#### } is a parse error
78}
79echo should not get here
80## stdout-json: ""
81## status: 2
82## OK mksh status: 1
83
84#### { is its own word, needs a space
85# bash and mksh give parse time error because of }
86# dash gives 127 as runtime error
87{ls; }
88echo "status=$?"
89## stdout-json: ""
90## status: 2
91## OK mksh status: 1
92
93#### } on the second line
94set -o errexit
95{ls;
96}
97## status: 127
98
99#### Invalid for loop variable name
100for i.j in a b c; do
101 echo hi
102done
103echo done
104## stdout-json: ""
105## status: 2
106## OK mksh status: 1
107## OK bash status: 0
108## BUG bash stdout: done
109
110#### bad var name globally isn't parsed like an assignment
111# bash and dash disagree on exit code.
112FOO-BAR=foo
113## status: 127
114
115#### bad var name in export
116# bash and dash disagree on exit code.
117export FOO-BAR=foo
118## status: 1
119## OK dash status: 2
120
121#### bad var name in local
122# bash and dash disagree on exit code.
123f() {
124 local FOO-BAR=foo
125}
126f
127## status: 1
128## OK dash status: 2
129
130#### misplaced parentheses are not a subshell
131echo a(b)
132## status: 2
133## OK mksh status: 1
134
135#### incomplete command sub
136$(x
137## status: 2
138## OK mksh status: 1
139
140#### incomplete backticks
141`x
142## status: 2
143## OK mksh status: 1
144
145#### misplaced ;;
146echo 1 ;; echo 2
147## stdout-json: ""
148## status: 2
149## OK mksh status: 1
150
151#### empty clause in [[
152
153# regression test for commit 451ca9e2b437e0326fc8155783d970a6f32729d8
154[[ || true ]]
155
156## status: 2
157## N-I dash status: 0
158## OK mksh status: 1
159
160#### interactive parse error (regression)
161flags=''
162case $SH in
163 bash*|*osh)
164 flags='--rcfile /dev/null'
165 ;;
166esac
167$SH $flags -i -c 'var=)'
168
169## status: 2
170## OK mksh status: 1
171
172#### array literal inside array is a parse error
173a=( inside=() )
174echo len=${#a[@]}
175## status: 2
176## stdout-json: ""
177## OK mksh status: 1
178## BUG bash status: 0
179## BUG bash stdout: len=0
180
181#### array literal inside loop is a parse error
182f() {
183 for x in a=(); do
184 echo x=$x
185 done
186 echo done
187}
188f
189## status: 2
190## stdout-json: ""
191## OK mksh status: 1
192
193#### array literal in case
194f() {
195 case a=() in
196 foo)
197 echo hi
198 ;;
199 esac
200}
201f
202## status: 2
203## stdout-json: ""
204## OK mksh status: 1
205
206#### %foo=() is parse error (regression)
207
208# Lit_VarLike and then (, but NOT at the beginning of a word.
209
210f() {
211 %foo=()
212}
213## status: 2
214## stdout-json: ""
215## OK mksh status: 1
216
217#### leading =word is not allowed regardless of shopt -s parse_equals
218=word
219## OK osh status: 2
220## status: 127
221
222#### echo =word is allowed
223echo =word
224## STDOUT:
225=word
226## END