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

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