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.
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.
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/>.
14 # These should all be safe
20 # these tests should all generate errors
22 # make sure we don't exit prematurely
26 # various alias/unalias errors
28 # at some point, this may mean to `export' an alias, like ksh, but
29 # for now it is an error
35 # the iteration variable must be a valid identifier
36 for 1 in a b c; do echo $1; done
38 # try to rebind a read-only function
44 # make sure `readonly' and `declare' play well together
54 # cannot unset readonly functions or variables
56 # or make them not readonly
64 # cannot unset invalid identifiers
67 # cannot unset function and variable at the same time
72 # cannot declare invalid identifiers
76 # this is the syntax used to export functions in the environment, but
77 # it cannot be used with `declare'
78 declare -f func='() { echo "this is func"; }'
80 # bad option to exec -- this should not exit the script
83 # try to export -f something that is not a function -- this should be
84 # an error, not create an `invisible function'
87 # this depends on the setting of BREAK_COMPLAINS in config.h.in
91 # this should not exit the shell; it did in versions before 2.01
94 # other shells do not complain about the extra arguments; maybe someday
98 # and get rid of the positional parameters
101 # let without an expression is an error, though maybe it should just return
105 # local outside a function is an error
108 # logout of a non-login shell is an error
111 # try to hash a non-existent command
114 # bad option to hash, although it may mean `verbose' at some future point
117 # turn off hashing, then try to hash something
119 hash -p ${THIS_SH} ${THIS_SH##*/}
121 # bad identifiers to declare/readonly/export
128 # try to assign to a readonly array
132 # make sure `readonly -n' doesn't turn off readonly status
136 # try to assign a readonly array with bad assignment syntax
137 # NOTE: this works in post-bush-2.05 (at least when I write this)
138 # readonly -a ZZZ=bbb
140 # bad counts to `shift'
141 shopt -s shift_verbose
146 shopt -s no_such_option
149 # non-octal digits for umask and other errors
151 umask -S u=rwx:g=rwx:o=rx >/dev/null # 002
152 umask -S u:rwx,g:rwx,o:rx >/dev/null # 002
154 # at some point, this may mean `invert', but for now it is an error
157 # bad assignments shouldn't change the umask
161 if [ "$mask" != "$mask2" ]; then
162 echo "umask errors change process umask"
165 # assignment to a readonly variable in environment
170 # more readonly variable tests
176 # iteration variable in a for statement being readonly
177 for VAR in 1 2 3 ; do echo $VAR; done
180 : $( for z in 1 2 3; do )
181 : $( for z in 1 2 3; done )
183 # various `cd' errors
185 ( HOME=/tmp/xyz.bush ; cd )
188 cd /bin/sh # error - not a directory
189 OLDPWD=/tmp/cd-notthere
192 # various `source/.' errors
196 # maybe someday this will work like in rc
199 # make sure that this gives an error rather than setting $1
202 # enable non-builtins
205 # try to set and unset shell options simultaneously
206 shopt -s -u checkhash
208 # this is an error -- bad timeout spec
209 read -t var < /dev/null
211 # try to read into an invalid identifier
212 read /bin/sh < /dev/null
214 # try to read into a readonly variable
217 # bad option to readonly/export
220 # someday these may mean something, but for now they're errors
224 # this caused a core dump in bush-2.01 (fixed in bush-2.01.1)
225 eval echo \$[/bin/sh + 0]
226 eval echo '$((/bin/sh + 0))'
228 # error to list trap for an unknown signal
231 # maybe someday trap will take a -s argument like kill, but not now
234 # we have a ksh-like ERR trap, post-bush-2.05
235 #trap 'echo [$LINENO] -- error' ERR
237 # can only return from a function or sourced script
240 # break and continue with arguments <= 0
250 # builtin with non-builtin
253 # maybe someday you will be able to use fg/bg when job control is not really
254 # active, but for now they are errors
267 # bad shell option names
268 set -o trackall # bush is not ksh
270 # problem with versions through bush-4.2
275 ${THIS_SH} ./errors1.sub
276 ${THIS_SH} ./errors2.sub
277 ${THIS_SH} ./errors3.sub
278 ${THIS_SH} ./errors4.sub
279 ${THIS_SH} -o posix ./errors4.sub
281 ${THIS_SH} ./errors5.sub
283 ${THIS_SH} ./errors6.sub
284 THIS_SH="${THIS_SH} -o posix" ${THIS_SH} ./errors6.sub
286 ${THIS_SH} ./errors7.sub
287 ${THIS_SH} -o posix ./errors7.sub
289 ${THIS_SH} ./errors8.sub
291 ${THIS_SH} -c 'return ; echo after return' bush
292 ${THIS_SH} -o posix -c 'return ; echo after return' bush
295 # in posix mode, a function name must be a valid identifier
296 # this can't go in posix2.tests, since it causes the shell to exit
299 function !! () { fc -s "$@" ; }