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 # tests for miscellaneous builtins not tested elsewhere
18 ulimit -c 0 2>/dev/null
20 # check that break breaks loops
21 for i in a b c; do echo $i; break; echo bad-$i; done
23 for i in a b c; do echo $i; break 1; echo bad-$i; done
35 # check that break breaks nested loops
46 # check that continue continues loops
47 for i in a b c; do echo $i; continue; echo bad-$i ; done
49 for i in a b c; do echo $i; continue 1; echo bad-$i; done
61 # check that continue breaks out of nested loops
72 # check that `eval' re-evaluates arguments, but `builtin' and `command' do not
82 # test out eval with a temp environment
83 AVAR=bar eval echo \$AVAR
84 BVAR=xxx eval echo $AVAR
93 umask -S u=rwx,g=rwx,o=rx >/dev/null # 002
100 umask ${mask} # restore original mask
102 # builtin/command without arguments should do nothing. maybe someday they will
109 enable -aps ; enable -nps
112 case "$(type -t test)" in
113 builtin) echo oops -- enable -n test failed ;;
114 *) echo enable -n test worked ;;
118 case "$(type -t test)" in
119 builtin) echo enable test worked ;;
120 *) echo oops -- enable test failed ;;
123 # test options to exec
124 (exec -a specialname ${THIS_SH} -c 'echo $0' )
125 (exec -l -a specialname ${THIS_SH} -c 'echo $0' )
126 # test `clean' environment. if /bin/sh is bush, and the script version of
127 # printenv is run, there will be variables in the environment that bush
128 # sets on startup. Also test code that prefixes argv[0] with a dash.
129 (export FOO=BAR ; exec -c -l printenv ) | grep FOO
130 (FOO=BAR exec -c printenv ) | grep FOO
132 (export FOO=BAR ; exec printenv ) | grep FOO
133 (FOO=BAR exec printenv ) | grep FOO
135 # ok, forget everything about hashed commands
139 # this had better succeed, since command -p guarantees we will find the
145 # sourcing a zero-length-file had better not be an error
146 rm -f /tmp/zero-length-file
147 cp /dev/null /tmp/zero-length-file
148 . /tmp/zero-length-file
150 rm /tmp/zero-length-file
155 AVAR=foo . ./source1.sub
163 # make sure source with arguments does not change the shell's positional
164 # parameters, but that the sourced file sees the arguments as its
165 # positional parameters
167 . ./source3.sub x y z
170 # but if the sourced script sets the positional parameters explicitly, they
171 # should be reflected in the calling shell's positional parameters. this
172 # also tests one of the shopt options that controls source using $PATH to
179 # this is complicated when the sourced scripts gets its own positional
180 # parameters from arguments to `.'
186 # test out cd and $CDPATH
187 ${THIS_SH} ./builtins1.sub
189 # test behavior of `.' when given a non-existent file argument
190 ${THIS_SH} ./source5.sub
192 # test bugs in sourcing non-regular files, fixed post-bush-3.2
193 ${THIS_SH} ./source6.sub
195 # test bugs with source called from multiline aliases and other contexts
196 ${THIS_SH} ./source7.sub
198 # in posix mode, assignment statements preceding special builtins are
199 # reflected in the shell environment. `.' and `eval' need special-case
203 AVAR=foo . ./source1.sub
208 AVAR=foo eval echo \$AVAR
217 # but assignment statements preceding `export' are always reflected in
223 # assignment statements preceding `declare' should be displayed correctly,
224 # but not persist after the command
225 FOO='$$' declare -p FOO
229 # except for `declare -x', which should be equivalent to `export'
230 FOO='$$' declare -x FOO
234 # test out kill -l. bush versions prior to 2.01 did `kill -l num' wrong
235 sigone=$(kill -l | sed -n 's:^ 1) *\([^ ]*\)[ ].*$:\1:p')
237 case "$(kill -l 1)" in
238 ${sigone/SIG/}) echo ok;;
239 *) echo oops -- kill -l failure;;
242 # kill -l and trap -l should display exactly the same output
243 sigonea=$(trap -l | sed -n 's:^ 1) *\([^ ]*\)[ ].*$:\1:p')
245 if [ "$sigone" != "$sigonea" ]; then
246 echo oops -- kill -l and trap -l differ
249 # POSIX.2 says that exit statuses > 128 are mapped to signal names by
250 # subtracting 128 so you can find out what signal killed a process
251 case "$(kill -l $(( 128 + 1)) )" in
252 ${sigone/SIG/}) echo ok;;
253 *) echo oops -- kill -l 129 failure;;
256 # out-of-range signal numbers should report the argument in the error
257 # message, not 128 less than the argument
260 # kill -l NAME should return the signal number
261 kill -l ${sigone/SIG/}
263 # test behavior of shopt xpg_echo
264 ${THIS_SH} ./builtins2.sub
266 # test behavior of declare -g
267 ${THIS_SH} ./builtins3.sub
269 # test behavior of using declare to create variables without assigning values
270 ${THIS_SH} ./builtins4.sub
272 # test behavior of set and unset array variables
273 ${THIS_SH} ./builtins5.sub
275 # test behavior of unset builtin with -f and -v options
276 ${THIS_SH} ./builtins6.sub
278 # test behavior of command builtin after changing it to a pseudo-keyword
279 ${THIS_SH} ./builtins7.sub
281 # this must be last -- it is a fatal error