OILS / spec / parse-errors.test.sh View on Github | oils.pub

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