apenwarr-redo/redo-sh.do
Avery Pennarun b993e449f8 shelltest: use a more magical magic number for success.
There may be some odd situation where a shell returns 0 despite not executing
the script correctly; now 0 is an error condition.
2011-04-17 23:39:53 -04:00

63 lines
1.4 KiB
Text

exec >&2
redo-ifchange t/shelltest.od
rm -rf $1.new $1/sh
mkdir $1.new
GOOD=
WARN=
for sh in dash sh /usr/xpg4/bin/sh ash posh mksh ksh ksh88 ksh93 pdksh \
bash zsh busybox; do
printf "%-30s" "Testing $sh..."
FOUND=`which $sh 2>/dev/null` || { echo "missing"; continue; }
# It's important for the file to actually be named 'sh'. Some
# shells (like bash and zsh) only go into POSIX-compatible mode if
# they have that name. If they're not in POSIX-compatible mode,
# they'll fail the test.
rm -f $1.new/sh
ln -s $FOUND $1.new/sh
set +e
( cd t && ../$1.new/sh shelltest.od >shelltest.tmp 2>&1 )
RV=$?
set -e
msgs=
crash=
while read line; do
#echo "line: '$line'" >&2
stripw=${line#warning: }
stripf=${line#failed: }
crash=$line
[ "$line" != "$stripw" ] && msgs="$msgs W$stripw"
[ "$line" != "$stripf" ] && msgs="$msgs F$stripf"
done <t/shelltest.tmp
rm -f t/shelltest.tmp
msgs=${msgs# }
crash=${crash##*:}
crash=${crash# }
case $RV in
40) echo "ok $msgs"; [ -n "$GOOD" ] || GOOD=$FOUND ;;
41) echo "failed $msgs" ;;
42) echo "warnings $msgs"; [ -n "$WARN" ] || WARN=$FOUND ;;
*) echo "crash $crash" ;;
esac
done
rm -rf $1 $1.new $3
if [ -n "$GOOD" ]; then
echo "Selected perfect shell: $GOOD"
mkdir $3
ln -s $GOOD $3/sh
elif [ -n "$WARN" ]; then
echo "Selected mostly good shell: $WARN"
mkdir $3
ln -s $WARN $3/sh
else
echo "No good shells found! Maybe install dash, bash, or zsh."
exit 1
fi