-# Simple test harness infrastructurei for BusyBox
+# Simple test harness infrastructure for BusyBox
#
# Copyright 2005 by Rob Landley
#
# number of failed tests.
# The "optional" function is used to skip certain tests, ala:
-# optional CONFIG_FEATURE_THINGY
+# optional FEATURE_THINGY
#
# The "optional" function checks the environment variable "OPTIONFLAGS",
# which is either empty (in which case it always clears SKIP) or
export SKIP=
# Helper for helpers. Oh my...
-test x"$ECHO" = x"" && {
+
+test x"$ECHO" != x"" || {
ECHO="echo"
test x"`echo -ne`" = x"" || {
# Compile and use a replacement 'echo' which understands -e -n
optional()
{
- option=`echo ":$OPTIONFLAGS:" | grep ":$1:"`
- # Not set?
- if [ -z "$1" ] || [ -z "$OPTIONFLAGS" ] || [ ${#option} -ne 0 ]
- then
- SKIP=
- return
- fi
- SKIP=1
+ SKIP=
+ while test "$1"; do
+ if test x"${OPTIONFLAGS/*:$1:*/y}" != x"y"; then
+ SKIP=1
+ return
+ fi
+ shift
+ done
}
# The testing function
testing()
{
NAME="$1"
- [ -z "$1" ] && NAME="$2"
+ [ -n "$1" ] || NAME="$2"
if [ $# -ne 5 ]
then
- echo "Test $NAME has wrong number of arguments (must be 5) ($# $*)" >&2
- exit
+ echo "Test $NAME has wrong number of arguments: $# (must be 5)" >&2
+ exit 1
fi
- [ -n "$DEBUG" ] && set -x
+ [ -z "$DEBUG" ] || set -x
if [ -n "$SKIP" ]
then
$ECHO -ne "$3" > expected
$ECHO -ne "$4" > input
- [ -z "$VERBOSE" ] || echo "echo '$5' | $2"
+ [ -z "$VERBOSE" ] || echo ======================
+ [ -z "$VERBOSE" ] || echo "echo -ne '$4' >input"
+ [ -z "$VERBOSE" ] || echo "echo -ne '$5' | $2"
$ECHO -ne "$5" | eval "$2" > actual
RETVAL=$?
- cmp expected actual >/dev/null 2>/dev/null
- if [ $? -ne 0 ]
+ if cmp expected actual >/dev/null 2>/dev/null
then
+ echo "PASS: $NAME"
+ else
FAILCOUNT=$(($FAILCOUNT + 1))
echo "FAIL: $NAME"
- [ -n "$VERBOSE" ] && diff -u expected actual
- else
- echo "PASS: $NAME"
+ [ -z "$VERBOSE" ] || diff -u expected actual
fi
rm -f input expected actual
- [ -n "$DEBUG" ] && set +x
+ [ -z "$DEBUG" ] || set +x
return $RETVAL
}