sh: Add some simple tests for ., exec and return from . script.

This commit is contained in:
Jilles Tjoelker 2010-05-28 22:08:34 +00:00
parent 911de7741d
commit bc4c1a0670
3 changed files with 62 additions and 0 deletions

View File

@ -0,0 +1,21 @@
# $FreeBSD$
failures=
failure() {
echo "Error at line $1" >&2
failures=x$failures
}
T=$(mktemp -d ${TMPDIR:-/tmp}/sh-test.XXXXXX) || exit
trap 'rm -rf $T' 0
cd $T || exit 3
unset x
echo 'x=2' >testscript
. ./testscript
[ "$x" = 2 ] || failure $LINENO
cd / || exit 3
x=1
PATH=$T:$PATH . testscript
[ "$x" = 2 ] || failure $LINENO
test -z "$failures"

View File

@ -0,0 +1,25 @@
# $FreeBSD$
failures=
failure() {
echo "Error at line $1" >&2
failures=x$failures
}
(
exec >/dev/null
echo bad
)
[ $? = 0 ] || failure $LINENO
(
exec sh -c 'exit 42'
echo bad
)
[ $? = 42 ] || failure $LINENO
(
exec /var/empty/nosuch
echo bad
) 2>/dev/null
[ $? = 127 ] || failure $LINENO
test -z "$failures"

View File

@ -0,0 +1,16 @@
# $FreeBSD$
failures=
failure() {
echo "Error at line $1" >&2
failures=x$failures
}
T=$(mktemp -d ${TMPDIR:-/tmp}/sh-test.XXXXXX) || exit
trap 'rm -rf $T' 0
cd $T || exit 3
echo 'return 42; exit 4' >testscript
. ./testscript
[ "$?" = 42 ] || failure $LINENO
test -z "$failures"