2010-12-21 04:19:50 -08:00
|
|
|
exec >&2
|
|
|
|
|
redo-ifchange t/shelltest.od
|
|
|
|
|
|
|
|
|
|
rm -rf $1.new $1/sh
|
|
|
|
|
mkdir $1.new
|
|
|
|
|
|
|
|
|
|
GOOD=
|
|
|
|
|
WARN=
|
|
|
|
|
|
2011-05-08 01:25:26 -04:00
|
|
|
# Note: list low-functionality, maximally POSIX-like shells before more
|
|
|
|
|
# powerful ones. We want weaker shells to take precedence, as long as they
|
|
|
|
|
# pass the tests, because weaker shells are more likely to point out when you
|
|
|
|
|
# use some non-portable feature.
|
2018-10-12 03:49:22 -04:00
|
|
|
for sh in dash /usr/xpg4/bin/sh ash posh mksh ksh ksh88 ksh93 pdksh \
|
2018-12-04 02:31:41 -05:00
|
|
|
zsh bash busybox /bin/sh; do
|
2011-03-23 11:24:17 -07:00
|
|
|
printf "%-30s" "Testing $sh..."
|
2011-01-02 11:49:51 -08:00
|
|
|
FOUND=`which $sh 2>/dev/null` || { echo "missing"; continue; }
|
2010-12-21 04:19:50 -08:00
|
|
|
|
2011-01-02 11:49:34 -08:00
|
|
|
# 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.
|
2010-12-21 04:19:50 -08:00
|
|
|
rm -f $1.new/sh
|
|
|
|
|
ln -s $FOUND $1.new/sh
|
|
|
|
|
|
|
|
|
|
set +e
|
2011-03-23 11:24:17 -07:00
|
|
|
( cd t && ../$1.new/sh shelltest.od >shelltest.tmp 2>&1 )
|
2010-12-21 04:19:50 -08:00
|
|
|
RV=$?
|
|
|
|
|
set -e
|
|
|
|
|
|
2011-03-23 11:24:17 -07:00
|
|
|
msgs=
|
|
|
|
|
crash=
|
|
|
|
|
while read line; do
|
|
|
|
|
#echo "line: '$line'" >&2
|
|
|
|
|
stripw=${line#warning: }
|
|
|
|
|
stripf=${line#failed: }
|
|
|
|
|
crash=$line
|
2011-05-08 01:25:26 -04:00
|
|
|
[ "$line" = "$stripw" ] || msgs="$msgs W$stripw"
|
|
|
|
|
[ "$line" = "$stripf" ] || msgs="$msgs F$stripf"
|
2011-03-23 11:24:17 -07:00
|
|
|
done <t/shelltest.tmp
|
|
|
|
|
rm -f t/shelltest.tmp
|
|
|
|
|
msgs=${msgs# }
|
|
|
|
|
crash=${crash##*:}
|
|
|
|
|
crash=${crash# }
|
|
|
|
|
|
2010-12-21 04:19:50 -08:00
|
|
|
case $RV in
|
2011-05-08 01:25:26 -04:00
|
|
|
40) echo "ok $msgs"; [ -n "$GOOD" ] || GOOD=$FOUND ;;
|
2011-03-23 11:24:17 -07:00
|
|
|
41) echo "failed $msgs" ;;
|
|
|
|
|
42) echo "warnings $msgs"; [ -n "$WARN" ] || WARN=$FOUND ;;
|
2011-04-17 23:39:53 -04:00
|
|
|
*) echo "crash $crash" ;;
|
2010-12-21 04:19:50 -08:00
|
|
|
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."
|
2011-05-08 01:25:26 -04:00
|
|
|
exit 13
|
2010-12-21 04:19:50 -08:00
|
|
|
fi
|