diff options
Diffstat (limited to 'tests/builtins.tests')
-rw-r--r-- | tests/builtins.tests | 80 |
1 files changed, 69 insertions, 11 deletions
diff --git a/tests/builtins.tests b/tests/builtins.tests index 0d80239b..9073ed55 100644 --- a/tests/builtins.tests +++ b/tests/builtins.tests @@ -4,6 +4,18 @@ set +o posix ulimit -c 0 2>/dev/null +# alias/unalias tests + +unalias -a +# this should return success, according to POSIX.2 +alias +echo alias: $? +alias foo=bar +unalias foo +# this had better return success, according to POSIX.2 +alias +echo alias: $? + # check that break breaks loops for i in a b c; do echo $i; break; echo bad-$i; done echo end-1 @@ -80,6 +92,8 @@ umask -S umask -S u=rwx,g=rwx,o=rx >/dev/null # 002 umask umask -S +umask -p +umask -p -S umask 0 umask -S umask ${mask} # restore original mask @@ -107,10 +121,11 @@ esac # test options to exec (exec -a specialname ${THIS_SH} -c 'echo $0' ) +(exec -l -a specialname ${THIS_SH} -c 'echo $0' ) # test `clean' environment. if /bin/sh is bash, and the script version of # printenv is run, there will be variables in the environment that bash -# sets on startup. -(export FOO=BAR ; exec -c printenv ) | grep FOO +# sets on startup. Also test code that prefixes argv[0] with a dash. +(export FOO=BAR ; exec -c -l printenv ) | grep FOO (FOO=BAR exec -c printenv ) | grep FOO (export FOO=BAR ; exec printenv ) | grep FOO @@ -120,24 +135,35 @@ esac hash -r hash +# this had better succeed, since command -p guarantees we will find the +# standard utilties +command -p hash rm + # check out source/. +# sourcing a zero-length-file had better not be an error +rm -f /tmp/zero-length-file +cp /dev/null /tmp/zero-length-file +. /tmp/zero-length-file +echo $? +rm /tmp/zero-length-file + AVAR=AVAR -. ./source.sub1 -AVAR=foo . ./source.sub1 +. ./source1.sub +AVAR=foo . ./source1.sub -. ./source.sub2 +. ./source2.sub echo $? set -- a b c -. ./source.sub3 +. ./source3.sub # make sure source with arguments does not change the shell's positional # parameters, but that the sourced file sees the arguments as its # positional parameters echo "$@" -. ./source.sub3 x y z +. ./source3.sub x y z echo "$@" # but if the sourced script sets the positional parameters explicitly, they @@ -146,25 +172,28 @@ echo "$@" # find the script echo "$@" shopt -u sourcepath -. source.sub4 +. source4.sub echo "$@" # this is complicated when the sourced scripts gets its own positional # parameters from arguments to `.' set -- a b c echo "$@" -. source.sub4 x y z +. source4.sub x y z echo "$@" # test out cd and $CDPATH ${THIS_SH} ./builtins.sub1 +# test behavior of `.' when given a non-existant file argument +${THIS_SH} ./source5.sub + # in posix mode, assignment statements preceding special builtins are # reflected in the shell environment. `.' and `eval' need special-case # code. set -o posix echo $AVAR -AVAR=foo . ./source.sub1 +AVAR=foo . ./source1.sub echo $AVAR AVAR=AVAR @@ -176,9 +205,26 @@ AVAR=AVAR echo $AVAR AVAR=foo : echo $AVAR +set +o posix + +# but assignment statements preceding `export' are always reflected in +# the environment +foo="" export foo +declare -p foo +unset foo + +# assignment statements preceding `declare' should be displayed correctly, +# but not persist after the command +FOO='$$' declare -p FOO +declare -p FOO +unset FOO + +# except for `declare -x', which should be equivalent to `export' +FOO='$$' declare -x FOO +declare -p FOO +unset FOO # test out kill -l. bash versions prior to 2.01 did `kill -l num' wrong -set +o posix sigone=$(kill -l | sed -n 's:^ 1) *\([^ ]*\)[ ].*$:\1:p') case "$(kill -l 1)" in @@ -186,6 +232,13 @@ ${sigone/SIG/}) echo ok;; *) echo oops -- kill -l failure;; esac +# kill -l and trap -l should display exactly the same output +sigonea=$(trap -l | sed -n 's:^ 1) *\([^ ]*\)[ ].*$:\1:p') + +if [ "$sigone" != "$sigonea" ]; then + echo oops -- kill -l and trap -l differ +fi + # POSIX.2 says that exit statuses > 128 are mapped to signal names by # subtracting 128 so you can find out what signal killed a process case "$(kill -l $(( 128 + 1)) )" in @@ -199,3 +252,8 @@ kill -l 4096 # kill -l NAME should return the signal number kill -l ${sigone/SIG/} + +# this must be last -- it is a fatal error +exit status + +echo after bad exit |