Allow one to regression test 'sh' changes without having to install

a potentially bad /bin/sh first.
This commit is contained in:
David E. O'Brien 2010-10-12 18:20:38 +00:00
parent 5ff14fa9b4
commit f3bf9b7a16
29 changed files with 100 additions and 82 deletions

View File

@ -62,4 +62,7 @@ syntax.c syntax.h: mksyntax
token.h: mktokens
sh ${.CURDIR}/mktokens
regress:
cd ${.CURDIR}/../../tools/regression/bin/sh && ${MAKE} SH=${.OBJDIR}/sh
.include <bsd.prog.mk>

View File

@ -1,4 +1,7 @@
# $FreeBSD$
# Allow one to specify the 'sh' to regress.
SH?= /bin/sh
all:
sh regress.sh
env SH=${SH} ${SH} regress.sh

View File

@ -22,7 +22,7 @@ set -e
set -- ${SPECIAL}
for cmd in "$@"
do
sh -c "v=:; while \$v; do v=false; command ${cmd}; done" >/dev/null
${SH} -c "v=:; while \$v; do v=false; command ${cmd}; done" >/dev/null
done
while :; do

View File

@ -12,7 +12,7 @@ failure() {
)
[ $? = 0 ] || failure $LINENO
(
exec sh -c 'exit 42'
exec ${SH} -c 'exit 42'
echo bad
)
[ $? = 42 ] || failure $LINENO

View File

@ -12,7 +12,7 @@ failure() {
)
[ $? = 0 ] || failure $LINENO
(
exec -- sh -c 'exit 42'
exec -- ${SH} -c 'exit 42'
echo bad
)
[ $? = 42 ] || failure $LINENO

View File

@ -8,7 +8,7 @@ T=$(mktemp -d sh-test.XXXXXX)
cd $T
mkfifo input output error
HISTFILE=/dev/null sh +m -i <input >output 2>error &
HISTFILE=/dev/null ${SH} +m -i <input >output 2>error &
{
# Syntax error
echo ')' >&3

View File

@ -8,7 +8,7 @@ T=$(mktemp -d sh-test.XXXXXX)
cd $T
mkfifo input output error
HISTFILE=/dev/null sh +m -i <input >output 2>error &
HISTFILE=/dev/null ${SH} +m -i <input >output 2>error &
exec 3>input
{
# Command not found, containing slash

View File

@ -4,11 +4,11 @@ test "$(trap 'echo trapped' EXIT; :)" = trapped || exit 1
test "$(trap 'echo trapped' EXIT; /usr/bin/true)" = trapped || exit 1
result=$(sh -c 'trap "echo trapped" EXIT; /usr/bin/false')
result=$(${SH} -c 'trap "echo trapped" EXIT; /usr/bin/false')
test $? -eq 1 || exit 1
test "$result" = trapped || exit 1
result=$(sh -c 'trap "echo trapped" EXIT; exec /usr/bin/false')
result=$(${SH} -c 'trap "echo trapped" EXIT; exec /usr/bin/false')
test $? -eq 1 || exit 1
test -z "$result" || exit 1

View File

@ -44,12 +44,12 @@ set -e
set -- ${SPECIAL}
for cmd in "$@"
do
sh -c "VAR=1; VAR=0 ${cmd}; exit \${VAR}" >/dev/null 2>&1
${SH} -c "VAR=1; VAR=0 ${cmd}; exit \${VAR}" >/dev/null 2>&1
done
# For other built-ins and utilites they do not.
set -- ${UTILS}
for cmd in "$@"
do
sh -c "VAR=0; VAR=1 ${cmd}; exit \${VAR}" >/dev/null 2>&1
${SH} -c "VAR=0; VAR=1 ${cmd}; exit \${VAR}" >/dev/null 2>&1
done

View File

@ -45,11 +45,11 @@ set -e
set -- ${SPECIAL}
for cmd in "$@"
do
sh -c "VAR=0; VAR=1 command ${cmd}; exit \${VAR}" >/dev/null 2>&1
${SH} -c "VAR=0; VAR=1 command ${cmd}; exit \${VAR}" >/dev/null 2>&1
done
set -- ${UTILS}
for cmd in "$@"
do
sh -c "VAR=0; VAR=1 command ${cmd}; exit \${VAR}" >/dev/null 2>&1
${SH} -c "VAR=0; VAR=1 command ${cmd}; exit \${VAR}" >/dev/null 2>&1
done

View File

@ -16,15 +16,15 @@ SPECIAL="break,\
unset foo"
# If there is no command word, the shell must abort on an assignment error.
sh -c "readonly a=0; a=2; exit 0" 2>/dev/null && exit 1
${SH} -c "readonly a=0; a=2; exit 0" 2>/dev/null && exit 1
# Special built-in utilities must abort on an assignment error.
set -- ${SPECIAL}
for cmd in "$@"
do
sh -c "readonly a=0; a=2 ${cmd}; exit 0" 2>/dev/null && exit 1
${SH} -c "readonly a=0; a=2 ${cmd}; exit 0" 2>/dev/null && exit 1
done
# Other utilities must not abort; we currently still execute them.
sh -c 'readonly a=0; a=1 true; exit $a' 2>/dev/null || exit 1
sh -c 'readonly a=0; a=1 command :; exit $a' 2>/dev/null || exit 1
${SH} -c 'readonly a=0; a=1 true; exit $a' 2>/dev/null || exit 1
${SH} -c 'readonly a=0; a=1 command :; exit $a' 2>/dev/null || exit 1

View File

@ -1,4 +1,4 @@
# $FreeBSD$
echo 'echo `for` echo ".BAD"CODE.' | sh +m -i 2>&1 | grep -q BADCODE && exit 1
echo 'echo `for` echo ".BAD"CODE.' | ${SH} +m -i 2>&1 | grep -q BADCODE && exit 1
exit 0

View File

@ -1,7 +1,7 @@
# $FreeBSD$
sh -c 'echo `echo .BA"DCODE.`
${SH} -c 'echo `echo .BA"DCODE.`
echo ".BAD"CODE.' 2>&1 | grep -q BADCODE && exit 1
echo '`"`' | sh -n 2>/dev/null && exit 1
echo '`'"'"'`' | sh -n 2>/dev/null && exit 1
echo '`"`' | ${SH} -n 2>/dev/null && exit 1
echo '`'"'"'`' | ${SH} -n 2>/dev/null && exit 1
exit 0

View File

@ -35,12 +35,12 @@ UTILS="alias -y,\
set -- ${SPECIAL}
for cmd in "$@"
do
sh -c "${cmd}; exit 0" 2>/dev/null && exit 1
${SH} -c "${cmd}; exit 0" 2>/dev/null && exit 1
done
# Other utilities must not abort.
set -- ${UTILS}
for cmd in "$@"
do
sh -c "${cmd}; exit 0" 2>/dev/null || exit 1
${SH} -c "${cmd}; exit 0" 2>/dev/null || exit 1
done

View File

@ -42,12 +42,12 @@ UTILS="alias,\
set -- ${SPECIAL}
for cmd in "$@"
do
sh -c "${cmd} > /; exit 0" 2>/dev/null && exit 1
${SH} -c "${cmd} > /; exit 0" 2>/dev/null && exit 1
done
# Other utilities must not abort.
set -- ${UTILS}
for cmd in "$@"
do
sh -c "${cmd} > /; exit 0" 2>/dev/null || exit 1
${SH} -c "${cmd} > /; exit 0" 2>/dev/null || exit 1
done

View File

@ -1,4 +1,4 @@
# $FreeBSD$
# sh should fail gracefully on this bad redirect
sh -c 'echo 1 >&$a' 2>/dev/null
${SH} -c 'echo 1 >&$a' 2>/dev/null

View File

@ -44,11 +44,11 @@ UTILS="alias,\
set -- ${SPECIAL}
for cmd in "$@"
do
sh -c "command ${cmd} > /; exit 0" 2>/dev/null || exit 1
${SH} -c "command ${cmd} > /; exit 0" 2>/dev/null || exit 1
done
set -- ${UTILS}
for cmd in "$@"
do
sh -c "command ${cmd} > /; exit 0" 2>/dev/null || exit 1
${SH} -c "command ${cmd} > /; exit 0" 2>/dev/null || exit 1
done

View File

@ -1,7 +1,7 @@
# $FreeBSD$
result=$(sh -c 'ps -p $$ -o comm=')
result=$(${SH} -c 'ps -p $$ -o comm=')
test "$result" = "ps" || exit 1
result=$(sh -c 'ps -p $$ -o comm=; :')
result=$(${SH} -c 'ps -p $$ -o comm=; :')
test "$result" = "sh" || exit 1

View File

@ -1,9 +1,9 @@
# $FreeBSD$
result=$(sh -c '(/bin/sleep 1)& sleep 0.1; ps -p $! -o comm=; kill $!')
result=$(${SH} -c '(/bin/sleep 1)& sleep 0.1; ps -p $! -o comm=; kill $!')
test "$result" = sleep || exit 1
result=$(sh -c '{ trap "echo trapped" EXIT; (/usr/bin/true); } & wait')
result=$(${SH} -c '{ trap "echo trapped" EXIT; (/usr/bin/true); } & wait')
test "$result" = trapped || exit 1
exit 0

View File

@ -1,4 +1,4 @@
# $FreeBSD$
MALLOC_OPTIONS=J sh -c 'g() { g() { :; }; :; }; g' &&
MALLOC_OPTIONS=J sh -c 'g() { unset -f g; :; }; g'
MALLOC_OPTIONS=J ${SH} -c 'g() { g() { :; }; :; }; g' &&
MALLOC_OPTIONS=J ${SH} -c 'g() { unset -f g; :; }; g'

View File

@ -10,7 +10,7 @@ brokenpipe=0
mkfifo fifo1 fifo2
{
{
exec sh -c 'exec <fifo1; read dummy'
exec ${SH} -c 'exec <fifo1; read dummy'
} 7<&- # fifo2 should be kept open, but not passed to programs
true
} 7<fifo2 &

View File

@ -6,17 +6,17 @@ set -- ${x?}
{ [ "$#" = 2 ] && [ "$1" = a ] && [ "$2" = b ]; } || exit 1
unset x
(echo ${x?abcdefg}) 2>&1 | grep -q abcdefg || exit 1
sh -c 'unset foo; echo ${foo?}' 2>/dev/null && exit 1
sh -c 'foo=; echo ${foo:?}' 2>/dev/null && exit 1
sh -c 'foo=; echo ${foo?}' >/dev/null || exit 1
sh -c 'foo=1; echo ${foo:?}' >/dev/null || exit 1
sh -c 'echo ${!?}' 2>/dev/null && exit 1
sh -c ':& echo ${!?}' >/dev/null || exit 1
sh -c 'echo ${#?}' >/dev/null || exit 1
sh -c 'echo ${*?}' 2>/dev/null && exit 1
sh -c 'echo ${*?}' sh x >/dev/null || exit 1
sh -c 'echo ${1?}' 2>/dev/null && exit 1
sh -c 'echo ${1?}' sh x >/dev/null || exit 1
sh -c 'echo ${2?}' sh x 2>/dev/null && exit 1
sh -c 'echo ${2?}' sh x y >/dev/null || exit 1
${SH} -c 'unset foo; echo ${foo?}' 2>/dev/null && exit 1
${SH} -c 'foo=; echo ${foo:?}' 2>/dev/null && exit 1
${SH} -c 'foo=; echo ${foo?}' >/dev/null || exit 1
${SH} -c 'foo=1; echo ${foo:?}' >/dev/null || exit 1
${SH} -c 'echo ${!?}' 2>/dev/null && exit 1
${SH} -c ':& echo ${!?}' >/dev/null || exit 1
${SH} -c 'echo ${#?}' >/dev/null || exit 1
${SH} -c 'echo ${*?}' 2>/dev/null && exit 1
${SH} -c 'echo ${*?}' ${SH} x >/dev/null || exit 1
${SH} -c 'echo ${1?}' 2>/dev/null && exit 1
${SH} -c 'echo ${1?}' ${SH} x >/dev/null || exit 1
${SH} -c 'echo ${2?}' ${SH} x 2>/dev/null && exit 1
${SH} -c 'echo ${2?}' ${SH} x y >/dev/null || exit 1
exit 0

View File

@ -1,29 +1,29 @@
# $FreeBSD$
sh -uc 'unset foo; echo $foo' 2>/dev/null && exit 1
sh -uc 'foo=; echo $foo' >/dev/null || exit 1
sh -uc 'foo=1; echo $foo' >/dev/null || exit 1
${SH} -uc 'unset foo; echo $foo' 2>/dev/null && exit 1
${SH} -uc 'foo=; echo $foo' >/dev/null || exit 1
${SH} -uc 'foo=1; echo $foo' >/dev/null || exit 1
# -/+/= are unaffected by set -u
sh -uc 'unset foo; echo ${foo-}' >/dev/null || exit 1
sh -uc 'unset foo; echo ${foo+}' >/dev/null || exit 1
sh -uc 'unset foo; echo ${foo=}' >/dev/null || exit 1
${SH} -uc 'unset foo; echo ${foo-}' >/dev/null || exit 1
${SH} -uc 'unset foo; echo ${foo+}' >/dev/null || exit 1
${SH} -uc 'unset foo; echo ${foo=}' >/dev/null || exit 1
# length/trimming are affected
sh -uc 'unset foo; echo ${#foo}' 2>/dev/null && exit 1
sh -uc 'foo=; echo ${#foo}' >/dev/null || exit 1
sh -uc 'unset foo; echo ${foo#?}' 2>/dev/null && exit 1
sh -uc 'foo=1; echo ${foo#?}' >/dev/null || exit 1
sh -uc 'unset foo; echo ${foo##?}' 2>/dev/null && exit 1
sh -uc 'foo=1; echo ${foo##?}' >/dev/null || exit 1
sh -uc 'unset foo; echo ${foo%?}' 2>/dev/null && exit 1
sh -uc 'foo=1; echo ${foo%?}' >/dev/null || exit 1
sh -uc 'unset foo; echo ${foo%%?}' 2>/dev/null && exit 1
sh -uc 'foo=1; echo ${foo%%?}' >/dev/null || exit 1
${SH} -uc 'unset foo; echo ${#foo}' 2>/dev/null && exit 1
${SH} -uc 'foo=; echo ${#foo}' >/dev/null || exit 1
${SH} -uc 'unset foo; echo ${foo#?}' 2>/dev/null && exit 1
${SH} -uc 'foo=1; echo ${foo#?}' >/dev/null || exit 1
${SH} -uc 'unset foo; echo ${foo##?}' 2>/dev/null && exit 1
${SH} -uc 'foo=1; echo ${foo##?}' >/dev/null || exit 1
${SH} -uc 'unset foo; echo ${foo%?}' 2>/dev/null && exit 1
${SH} -uc 'foo=1; echo ${foo%?}' >/dev/null || exit 1
${SH} -uc 'unset foo; echo ${foo%%?}' 2>/dev/null && exit 1
${SH} -uc 'foo=1; echo ${foo%%?}' >/dev/null || exit 1
sh -uc 'echo $!' 2>/dev/null && exit 1
sh -uc ':& echo $!' >/dev/null || exit 1
sh -uc 'echo $#' >/dev/null || exit 1
sh -uc 'echo $1' 2>/dev/null && exit 1
sh -uc 'echo $1' sh x >/dev/null || exit 1
sh -uc 'echo $2' sh x 2>/dev/null && exit 1
sh -uc 'echo $2' sh x y >/dev/null || exit 1
${SH} -uc 'echo $!' 2>/dev/null && exit 1
${SH} -uc ':& echo $!' >/dev/null || exit 1
${SH} -uc 'echo $#' >/dev/null || exit 1
${SH} -uc 'echo $1' 2>/dev/null && exit 1
${SH} -uc 'echo $1' ${SH} x >/dev/null || exit 1
${SH} -uc 'echo $2' ${SH} x 2>/dev/null && exit 1
${SH} -uc 'echo $2' ${SH} x y >/dev/null || exit 1
exit 0

View File

@ -4,7 +4,7 @@
goodfile=/var/empty/sh-test-goodfile
mailfile=/var/empty/sh-test-mailfile
T=$(mktemp sh-test.XXXXXX) || exit
MAIL=$mailfile ktrace -i -f "$T" sh -c "[ -s $goodfile ]" 2>/dev/null
MAIL=$mailfile ktrace -i -f "$T" ${SH} -c "[ -s $goodfile ]" 2>/dev/null
if ! grep -q $goodfile "$T"; then
# ktrace problem
rc=0

View File

@ -4,7 +4,7 @@
goodfile=/var/empty/sh-test-goodfile
mailfile=/var/empty/sh-test-mailfile
T=$(mktemp sh-test.XXXXXX) || exit
ENV=$goodfile MAIL=$mailfile ktrace -i -f "$T" sh +m -i </dev/null >/dev/null 2>&1
ENV=$goodfile MAIL=$mailfile ktrace -i -f "$T" ${SH} +m -i </dev/null >/dev/null 2>&1
if ! grep -q $goodfile "$T"; then
# ktrace problem
rc=0

View File

@ -3,9 +3,9 @@
cd / || exit 3
failures=0
[ "$(PWD=foo sh -c 'pwd')" = / ] || : $((failures += 1))
[ "$(PWD=/var/empty sh -c 'pwd')" = / ] || : $((failures += 1))
[ "$(PWD=/var/empty/foo sh -c 'pwd')" = / ] || : $((failures += 1))
[ "$(PWD=/bin/ls sh -c 'pwd')" = / ] || : $((failures += 1))
[ "$(PWD=foo ${SH} -c 'pwd')" = / ] || : $((failures += 1))
[ "$(PWD=/var/empty ${SH} -c 'pwd')" = / ] || : $((failures += 1))
[ "$(PWD=/var/empty/foo ${SH} -c 'pwd')" = / ] || : $((failures += 1))
[ "$(PWD=/bin/ls ${SH} -c 'pwd')" = / ] || : $((failures += 1))
exit $((failures != 0))

View File

@ -12,13 +12,13 @@ cd link
[ "$PWD" = "$TP/link" ]
[ "$(pwd)" = "$TP/link" ]
[ "$(pwd -P)" = "$TP/test1" ]
[ "$(sh -c pwd)" = "$TP/link" ]
[ "$(sh -c pwd\ -P)" = "$TP/test1" ]
[ "$(${SH} -c pwd)" = "$TP/link" ]
[ "$(${SH} -c pwd\ -P)" = "$TP/test1" ]
cd ..
[ "$(pwd)" = "$TP" ]
cd -P link
[ "$PWD" = "$TP/test1" ]
[ "$(pwd)" = "$TP/test1" ]
[ "$(pwd -P)" = "$TP/test1" ]
[ "$(sh -c pwd)" = "$TP/test1" ]
[ "$(sh -c pwd\ -P)" = "$TP/test1" ]
[ "$(${SH} -c pwd)" = "$TP/test1" ]
[ "$(${SH} -c pwd\ -P)" = "$TP/test1" ]

View File

@ -1,12 +1,18 @@
# $FreeBSD$
if [ -z "${SH}" ]; then
echo '${SH} is not set, please correct and re-run.'
exit 1
fi
export SH=${SH}
COUNTER=1
do_test() {
local c
c=${COUNTER}
COUNTER=$((COUNTER+1))
sh $1 > tmp.stdout 2> tmp.stderr
${SH} $1 > tmp.stdout 2> tmp.stderr
if [ $? -ne $2 ]; then
echo "not ok ${c} - ${1} # wrong exit status"
rm tmp.stdout tmp.stderr

View File

@ -1,6 +1,12 @@
#!/bin/sh
# $FreeBSD$
if [ -z "${SH}" ]; then
echo '${SH} is not set, please correct and re-run.'
exit 1
fi
export SH=${SH}
cd `dirname $0`
sh regress.sh
${SH} regress.sh