2007-12-16 15:55:34 -08:00
|
|
|
#!/bin/bash
|
|
|
|
|
2019-01-19 15:00:26 -08:00
|
|
|
source scripts/runtest.sh
|
|
|
|
source scripts/portability.sh
|
2018-12-02 14:22:41 -08:00
|
|
|
|
2023-07-10 22:34:45 -07:00
|
|
|
# Kill child processes when we exit
|
2014-09-20 11:09:14 -07:00
|
|
|
trap 'kill $(jobs -p) 2>/dev/null; exit 1' INT
|
|
|
|
|
2023-07-10 22:34:45 -07:00
|
|
|
# Create working directory
|
|
|
|
TOPDIR="$PWD"
|
|
|
|
export FILES="$PWD"/tests/files PREFIX=generated/testdir
|
2022-11-21 21:14:40 -08:00
|
|
|
rm -rf "$PREFIX"
|
|
|
|
mkdir -p "$PREFIX"/testdir
|
2007-12-16 15:55:34 -08:00
|
|
|
|
2023-07-10 22:34:45 -07:00
|
|
|
# Populate working directory
|
2008-05-04 17:44:39 -07:00
|
|
|
if [ -z "$TEST_HOST" ]
|
2007-12-16 15:55:34 -08:00
|
|
|
then
|
2013-10-14 22:57:39 -07:00
|
|
|
if [ $# -ne 0 ]
|
|
|
|
then
|
2022-11-21 21:14:40 -08:00
|
|
|
scripts/single.sh "$@" || exit 1
|
2013-10-14 22:57:39 -07:00
|
|
|
else
|
2022-11-21 21:14:40 -08:00
|
|
|
scripts/install.sh --symlink --force || exit 1
|
2013-10-14 22:57:39 -07:00
|
|
|
fi
|
2007-12-16 15:55:34 -08:00
|
|
|
fi
|
|
|
|
|
2023-07-10 22:34:45 -07:00
|
|
|
# Add prefix to $PATH
|
2022-11-21 21:14:40 -08:00
|
|
|
export -n PREFIX
|
|
|
|
cd "$PREFIX"
|
2023-07-10 22:34:45 -07:00
|
|
|
PATH="$PWD:$PATH" TESTDIR="$PWD"
|
2016-01-15 14:58:42 -08:00
|
|
|
export LC_COLLATE=C
|
2007-12-16 15:55:34 -08:00
|
|
|
|
2023-07-10 22:34:45 -07:00
|
|
|
# Collection OPTIONFLAGS for optional()
|
2018-12-02 14:22:41 -08:00
|
|
|
[ -f "$TOPDIR/generated/config.h" ] &&
|
2022-09-03 04:55:09 -07:00
|
|
|
export OPTIONFLAGS=:$($SED -nr 's/^#define CFG_(.*) 1$/\1/p' "$TOPDIR/generated/config.h" | tr '\n' :)
|
2007-12-16 15:55:34 -08:00
|
|
|
|
2023-07-10 22:34:45 -07:00
|
|
|
# Run a test file in $TESTDIR/testdir with $CMDNAME and $C set, parse $FAILCOUNT
|
2016-10-18 14:52:17 -07:00
|
|
|
do_test()
|
|
|
|
{
|
2023-07-10 22:34:45 -07:00
|
|
|
# reset testdir
|
2021-06-02 04:46:47 -07:00
|
|
|
cd "$TESTDIR" && rm -rf testdir continue && mkdir testdir && cd testdir ||
|
|
|
|
exit 1
|
2023-07-10 22:34:45 -07:00
|
|
|
|
|
|
|
# set CMDNAME to base name of test file, and C to full path to command
|
|
|
|
CMDNAME="${1##*/}" CMDNAME="${CMDNAME%.test}"
|
2017-07-22 15:00:11 -07:00
|
|
|
if [ -z "$TEST_HOST" ]
|
|
|
|
then
|
2019-03-10 16:17:16 -07:00
|
|
|
C="$TESTDIR/$CMDNAME"
|
2022-09-03 04:55:09 -07:00
|
|
|
[ ! -e "$C" ] && echo "$SHOWSKIP: $CMDNAME disabled" && return
|
2021-07-24 10:13:44 -07:00
|
|
|
C="$(dirname $(realpath "$C"))/$CMDNAME"
|
2019-06-26 21:42:14 -07:00
|
|
|
else
|
|
|
|
C="$(which $CMDNAME 2>/dev/null)"
|
2020-05-12 23:28:09 -07:00
|
|
|
[ -z "$C" ] && printf '%s\n' "$SHOWSKIP: no $CMDNAME" && return
|
2016-10-18 14:52:17 -07:00
|
|
|
fi
|
2019-03-10 16:17:16 -07:00
|
|
|
|
2023-07-10 22:34:45 -07:00
|
|
|
# Run command.test in a subshell
|
2022-07-04 02:34:58 -07:00
|
|
|
(. "$1"; cd "$TESTDIR"; echo "$FAILCOUNT" > continue)
|
2021-06-02 04:46:47 -07:00
|
|
|
cd "$TESTDIR"
|
2022-07-04 02:34:58 -07:00
|
|
|
[ -e continue ] && FAILCOUNT=$(($(cat continue)+$FAILCOUNT)) || exit 1
|
2016-10-18 14:52:17 -07:00
|
|
|
}
|
|
|
|
|
2023-07-10 22:34:45 -07:00
|
|
|
# Run each test listed on command line or else all tests with executable bit set
|
2007-12-16 15:55:34 -08:00
|
|
|
if [ $# -ne 0 ]
|
|
|
|
then
|
|
|
|
for i in "$@"
|
|
|
|
do
|
2016-10-18 14:52:17 -07:00
|
|
|
do_test "$TOPDIR"/tests/$i.test
|
2007-12-16 15:55:34 -08:00
|
|
|
done
|
|
|
|
else
|
2014-09-20 11:09:14 -07:00
|
|
|
for i in "$TOPDIR"/tests/*.test
|
2007-12-16 15:55:34 -08:00
|
|
|
do
|
2018-11-20 15:50:05 -08:00
|
|
|
[ -z "$TEST_ALL" ] && [ ! -x "$i" ] && continue
|
2019-03-10 16:17:16 -07:00
|
|
|
do_test "$i"
|
2007-12-16 15:55:34 -08:00
|
|
|
done
|
|
|
|
fi
|
2020-06-16 19:08:21 -07:00
|
|
|
|
|
|
|
[ $FAILCOUNT -eq 0 ]
|