+TESTTORUN=''
+while [ -n "$1" ]; do
+ if [ "$1" = "-q" ]; then
+ export MSGLEVEL=2
+ elif [ "$1" = "-v" ]; then
+ export MSGLEVEL=4
+ elif [ "$1" = '--color=no' ]; then
+ export MSGCOLOR='NO'
+ elif [ "$1" = '--color=yes' ]; then
+ export MSGCOLOR='YES'
+ elif [ "$1" = '--color' ]; then
+ export MSGCOLOR="$(echo "$2" | tr 'a-z' 'A-Z')"
+ shift
+ elif [ "$1" = '--level' ]; then
+ export MSGLEVEL=$2
+ shift
+ elif [ "$1" = '-j' ]; then
+ APT_TEST_JOBS=$2
+ shift
+ elif [ -x "$1" ]; then
+ TESTTORUN="$1"
+ else
+ echo >&2 "WARNING: Unknown parameter »$1« will be ignored"
+ fi
+ shift
+done
+export MSGLEVEL="${MSGLEVEL:-3}"
+
+if [ "${MSGCOLOR:-YES}" = 'YES' ]; then
+ if [ ! -t 1 ]; then # but check that we output to a terminal
+ export MSGCOLOR='NO'
+ fi
+fi
+if [ "$MSGCOLOR" != 'NO' ]; then
+ CTEST='\033[1;32m'
+ CHIGH='\033[1;35m'
+ CRESET='\033[0m'
+else
+ CTEST=''
+ CHIGH=''
+ CRESET=''
+fi
+
+if [ -n "$TESTTORUN" ]; then
+ # collecting the output of one test to have it together
+ OUTPUT="$(mktemp)"
+ CURRENTTRAP="rm -f \"$OUTPUT\"; $CURRENTTRAP"
+ trap "$CURRENTTRAP" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
+ {
+ if [ "$MSGLEVEL" -le 2 ]; then
+ printf "${CTEST}Testcase ${CHIGH}${TESTTORUN##*/}${CRESET}: "
+ else
+ printf "${CTEST}Run Testcase ${CHIGH}${TESTTORUN##*/}${CRESET}\n"
+ fi
+ if ! "$TESTTORUN"; then
+ FAIL='yes'
+ if [ "$MSGLEVEL" -le 2 ]; then
+ printf >&2 "\n${CHIGH}Running ${TESTTORUN##*/} -> FAILED${CRESET}"
+ else
+ echo >&2 "${CHIGH}Running ${TESTTORUN##*/} -> FAILED${CRESET}"
+ fi
+ fi
+ if [ "$MSGLEVEL" -le 2 ]; then
+ echo
+ fi
+ } >"$OUTPUT" 2>&1
+ # without we end up getting stepped output 'randomly'
+ stty sane
+ cat >&2 "$OUTPUT"
+ stty sane
+ if [ "$FAIL" = 'yes' ]; then
+ exit 1
+ else
+ exit 0
+ fi
+fi
+