]>
Commit | Line | Data |
---|---|---|
8868edaf CR |
1 | # This program is free software: you can redistribute it and/or modify |
2 | # it under the terms of the GNU General Public License as published by | |
3 | # the Free Software Foundation, either version 3 of the License, or | |
4 | # (at your option) any later version. | |
5 | # | |
6 | # This program is distributed in the hope that it will be useful, | |
7 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
8 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
9 | # GNU General Public License for more details. | |
10 | # | |
11 | # You should have received a copy of the GNU General Public License | |
12 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
13 | # | |
d166f048 JA |
14 | # These should all be safe |
15 | LC_ALL=C | |
16 | LC_CTYPE=C | |
17 | LC_COLLATE=C | |
18 | LC_MESSAGES=C | |
19 | ||
20 | # these tests should all generate errors | |
21 | ||
22 | # make sure we don't exit prematurely | |
23 | set +e | |
24 | set +o posix | |
25 | ||
cce855bc JA |
26 | # various alias/unalias errors |
27 | ||
28 | # at some point, this may mean to `export' an alias, like ksh, but | |
29 | # for now it is an error | |
30 | alias -x foo=barz | |
31 | unalias -x fooaha | |
32 | alias hoowah | |
33 | unalias hoowah | |
34 | ||
d166f048 JA |
35 | # the iteration variable must be a valid identifier |
36 | for 1 in a b c; do echo $1; done | |
37 | ||
38 | # try to rebind a read-only function | |
39 | func() | |
40 | { | |
41 | echo func | |
42 | } | |
43 | readonly -f func | |
44 | # make sure `readonly' and `declare' play well together | |
45 | declare -Fr | |
46 | func() | |
47 | { | |
48 | echo bar | |
49 | } | |
50 | ||
cce855bc JA |
51 | # bad option |
52 | unset -x func | |
53 | ||
d166f048 JA |
54 | # cannot unset readonly functions or variables |
55 | unset -f func | |
56 | # or make them not readonly | |
57 | declare -fr func | |
58 | declare -f +r func | |
59 | ||
4491c030 CR |
60 | # cannot use declare -f in combination with other attributes |
61 | a() { echo a; } | |
62 | declare -f -a a | |
63 | declare -f -i b c | |
64 | ||
d166f048 JA |
65 | XPATH=$PATH |
66 | declare -r XPATH | |
67 | unset -v XPATH | |
68 | ||
69 | # cannot unset invalid identifiers | |
70 | unset /bin/sh | |
71 | ||
cce855bc JA |
72 | # cannot unset function and variable at the same time |
73 | unset -f -v SHELL | |
74 | ||
d166f048 JA |
75 | # bad option |
76 | declare -z | |
77 | # cannot declare invalid identifiers | |
78 | declare -- -z | |
79 | declare /bin/sh | |
80 | ||
81 | # this is the syntax used to export functions in the environment, but | |
82 | # it cannot be used with `declare' | |
83 | declare -f func='() { echo "this is func"; }' | |
84 | ||
cce855bc JA |
85 | # bad option to exec -- this should not exit the script |
86 | exec -i /bin/sh | |
87 | ||
d166f048 JA |
88 | # try to export -f something that is not a function -- this should be |
89 | # an error, not create an `invisible function' | |
90 | export -f XPATH | |
91 | ||
92 | # this depends on the setting of BREAK_COMPLAINS in config.h.in | |
93 | break | |
94 | continue | |
95 | ||
96 | # this should not exit the shell; it did in versions before 2.01 | |
97 | shift label | |
98 | ||
99 | # other shells do not complain about the extra arguments; maybe someday | |
100 | # we won't either | |
101 | set -- a b c | |
102 | shift $# label | |
103 | # and get rid of the positional parameters | |
104 | shift $# | |
105 | ||
106 | # let without an expression is an error, though maybe it should just return | |
107 | # success | |
108 | let | |
109 | ||
110 | # local outside a function is an error | |
111 | local | |
112 | ||
cce855bc JA |
113 | # logout of a non-login shell is an error |
114 | logout | |
115 | ||
8868edaf | 116 | # try to hash a non-existent command |
d166f048 JA |
117 | hash notthere |
118 | ||
cce855bc JA |
119 | # bad option to hash, although it may mean `verbose' at some future point |
120 | hash -v | |
121 | ||
d166f048 JA |
122 | # turn off hashing, then try to hash something |
123 | set +o hashall | |
124 | hash -p ${THIS_SH} ${THIS_SH##*/} | |
125 | ||
126 | # bad identifiers to declare/readonly/export | |
127 | export AA[4] | |
128 | readonly AA[4] | |
129 | ||
130 | declare -a AA | |
131 | unset AA[-2] | |
132 | ||
133 | # try to assign to a readonly array | |
134 | declare -r AA | |
135 | AA=( one two three ) | |
136 | ||
cce855bc JA |
137 | # make sure `readonly -n' doesn't turn off readonly status |
138 | readonly -n AA | |
139 | AA=(one two three) | |
140 | ||
141 | # try to assign a readonly array with bad assignment syntax | |
f73dda09 JA |
142 | # NOTE: this works in post-bash-2.05 (at least when I write this) |
143 | # readonly -a ZZZ=bbb | |
cce855bc | 144 | |
d166f048 JA |
145 | # bad counts to `shift' |
146 | shopt -s shift_verbose | |
147 | shift $(( $# + 5 )) | |
148 | shift -2 | |
149 | ||
150 | # bad shell options | |
151 | shopt -s no_such_option | |
152 | shopt no_such_option | |
153 | ||
154 | # non-octal digits for umask and other errors | |
155 | umask 09 | |
156 | umask -S u=rwx:g=rwx:o=rx >/dev/null # 002 | |
157 | umask -S u:rwx,g:rwx,o:rx >/dev/null # 002 | |
cce855bc JA |
158 | |
159 | # at some point, this may mean `invert', but for now it is an error | |
160 | umask -i | |
d166f048 | 161 | |
bb70624e JA |
162 | # bad assignments shouldn't change the umask |
163 | mask=$(umask) | |
164 | umask g=u | |
165 | mask2=$(umask) | |
166 | if [ "$mask" != "$mask2" ]; then | |
167 | echo "umask errors change process umask" | |
168 | fi | |
169 | ||
d166f048 JA |
170 | # assignment to a readonly variable in environment |
171 | VAR=4 | |
172 | readonly VAR | |
173 | VAR=7 : | |
174 | ||
175 | # more readonly variable tests | |
176 | declare VAR=88 | |
177 | declare +r VAR | |
178 | ||
179 | declare -p unset | |
180 | ||
181 | # iteration variable in a for statement being readonly | |
182 | for VAR in 1 2 3 ; do echo $VAR; done | |
183 | ||
6c1407d2 CR |
184 | # parser errors; caught early so we have to run them in subshells |
185 | ${THIS_SH} -c ': $( for z in 1 2 3; do )' comsub | |
186 | ${THIS_SH} -c ': $( for z in 1 2 3; done )' comsub | |
d166f048 JA |
187 | |
188 | # various `cd' errors | |
189 | ( unset HOME ; cd ) | |
cce855bc JA |
190 | ( HOME=/tmp/xyz.bash ; cd ) |
191 | # errors from cd | |
192 | cd - | |
193 | cd /bin/sh # error - not a directory | |
194 | OLDPWD=/tmp/cd-notthere | |
195 | cd - | |
d166f048 JA |
196 | |
197 | # various `source/.' errors | |
198 | . | |
199 | source | |
200 | ||
201 | # maybe someday this will work like in rc | |
202 | . -i /dev/tty | |
203 | ||
204 | # make sure that this gives an error rather than setting $1 | |
205 | set -q | |
206 | ||
207 | # enable non-builtins | |
208 | enable sh bash | |
209 | ||
210 | # try to set and unset shell options simultaneously | |
211 | shopt -s -u checkhash | |
212 | ||
bb70624e | 213 | # this is an error -- bad timeout spec |
cce855bc JA |
214 | read -t var < /dev/null |
215 | ||
d166f048 JA |
216 | # try to read into an invalid identifier |
217 | read /bin/sh < /dev/null | |
218 | ||
219 | # try to read into a readonly variable | |
220 | read VAR < /dev/null | |
221 | ||
cce855bc JA |
222 | # bad option to readonly/export |
223 | readonly -x foo | |
224 | ||
d166f048 JA |
225 | # someday these may mean something, but for now they're errors |
226 | eval -i "echo $-" | |
227 | command -i "echo $-" | |
228 | ||
cce855bc JA |
229 | # this caused a core dump in bash-2.01 (fixed in bash-2.01.1) |
230 | eval echo \$[/bin/sh + 0] | |
231 | eval echo '$((/bin/sh + 0))' | |
232 | ||
d166f048 JA |
233 | # error to list trap for an unknown signal |
234 | trap -p NOSIG | |
235 | ||
236 | # maybe someday trap will take a -s argument like kill, but not now | |
237 | trap -p -s NOSIG | |
238 | ||
f73dda09 JA |
239 | # we have a ksh-like ERR trap, post-bash-2.05 |
240 | #trap 'echo [$LINENO] -- error' ERR | |
d166f048 JA |
241 | |
242 | # can only return from a function or sourced script | |
243 | return 2 | |
244 | ||
245 | # break and continue with arguments <= 0 | |
246 | for z in 1 2 3; do | |
247 | break 0 | |
248 | echo $x | |
249 | done | |
250 | for z in 1 2 3; do | |
251 | continue 0 | |
252 | echo $x | |
253 | done | |
254 | ||
255 | # builtin with non-builtin | |
256 | builtin bash | |
257 | ||
258 | # maybe someday you will be able to use fg/bg when job control is not really | |
259 | # active, but for now they are errors | |
260 | bg | |
261 | fg | |
262 | ||
263 | # argument required | |
264 | kill -s | |
265 | # bad argument | |
266 | kill -S | |
cce855bc JA |
267 | # null argument |
268 | kill -INT '' | |
269 | # argument required | |
270 | kill -INT | |
271 | ||
272 | # bad shell option names | |
273 | set -o trackall # bash is not ksh | |
d166f048 | 274 | |
ac50fbac CR |
275 | # problem with versions through bash-4.2 |
276 | readonly xx=5 | |
277 | echo $((xx=5)) | |
278 | echo $? | |
279 | ||
280 | ${THIS_SH} ./errors1.sub | |
281 | ${THIS_SH} ./errors2.sub | |
282 | ${THIS_SH} ./errors3.sub | |
a0c0a00f CR |
283 | ${THIS_SH} ./errors4.sub |
284 | ${THIS_SH} -o posix ./errors4.sub | |
285 | ||
286 | ${THIS_SH} ./errors5.sub | |
287 | ||
288 | ${THIS_SH} ./errors6.sub | |
289 | THIS_SH="${THIS_SH} -o posix" ${THIS_SH} ./errors6.sub | |
ac50fbac | 290 | |
d233b485 CR |
291 | ${THIS_SH} ./errors7.sub |
292 | ${THIS_SH} -o posix ./errors7.sub | |
293 | ||
294 | ${THIS_SH} ./errors8.sub | |
f36c8c8e | 295 | ${THIS_SH} ./errors9.sub |
d233b485 | 296 | |
8868edaf CR |
297 | ${THIS_SH} -c 'return ; echo after return' bash |
298 | ${THIS_SH} -o posix -c 'return ; echo after return' bash | |
299 | ||
d166f048 JA |
300 | # this must be last! |
301 | # in posix mode, a function name must be a valid identifier | |
302 | # this can't go in posix2.tests, since it causes the shell to exit | |
303 | # immediately | |
304 | set -o posix | |
305 | function !! () { fc -s "$@" ; } | |
306 | set +o posix | |
307 | ||
308 | echo end |