Test infrastructure: collate make "test_single" and "make tests" into common

function, and add $C variable with an absolute path to the command being tested
(you need to call things like printf by path to avoid shell builtins, might as
well be consistent).
This commit is contained in:
Rob Landley 2016-10-18 16:52:17 -05:00
parent 54e8313d6a
commit ee14fc396d

View File

@ -26,25 +26,35 @@ export LC_COLLATE=C
. "$TOPDIR"/scripts/runtest.sh . "$TOPDIR"/scripts/runtest.sh
[ -f "$TOPDIR/generated/config.h" ] && export OPTIONFLAGS=:$(echo $(sed -nr 's/^#define CFG_(.*) 1/\1/p' "$TOPDIR/generated/config.h") | sed 's/ /:/g') [ -f "$TOPDIR/generated/config.h" ] && export OPTIONFLAGS=:$(echo $(sed -nr 's/^#define CFG_(.*) 1/\1/p' "$TOPDIR/generated/config.h") | sed 's/ /:/g')
do_test()
{
CMDNAME="${1##*/}"
CMDNAME="${CMDNAME%.test}"
[ -z "$2" ] && C="$(readlink -f ../$CMDNAME)" || C="$(which $CMDNAME)"
if [ ! -z "$C" ]
then
. "$1"
else
echo "$CMDNAME disabled"
fi
}
if [ $# -ne 0 ] if [ $# -ne 0 ]
then then
for i in "$@" for i in "$@"
do do
CMDNAME="${i##*/}" do_test "$TOPDIR"/tests/$i.test
CMDNAME="${CMDNAME%.test}"
. "$TOPDIR"/tests/$i.test
done done
else else
for i in "$TOPDIR"/tests/*.test for i in "$TOPDIR"/tests/*.test
do do
CMDNAME="${i##*/}" if [ -z "$TEST_HOST" ]
CMDNAME="${CMDNAME%.test}"
if [ -h ../$CMDNAME ] || [ ! -z "$TEST_HOST" ]
then then
cd .. && rm -rf testdir && mkdir testdir && cd testdir || exit 1 do_test "$i" 1
. $i
else else
echo "$CMDNAME disabled" rm -rf testdir && mkdir testdir && cd testdir || exit 1
do_test "$i"
cd ..
fi fi
done done
fi fi