6 if [ "$1" = "-q" ]; then
8 elif [ "$1" = "-qq" ]; then
10 elif [ "$1" = "-v" ]; then
12 elif [ "$1" = '--color=no' ]; then
14 elif [ "$1" = '--color=yes' ]; then
16 elif [ "$1" = '--color' ]; then
17 export MSGCOLOR
="$(echo "$2" | tr 'a-z' 'A-Z')"
19 elif [ "$1" = '--level' ]; then
22 elif [ "$1" = '-j' ]; then
25 elif [ -x "$1" ]; then
28 echo >&2 "WARNING: Unknown parameter »$1« will be ignored"
32 export MSGLEVEL
="${MSGLEVEL:-3}"
34 if [ "${MSGCOLOR:-YES}" = 'YES' ]; then
35 if [ ! -t 1 ]; then # but check that we output to a terminal
39 if [ "$MSGCOLOR" != 'NO' ]; then
49 if [ -n "$TESTTORUN" ]; then
50 # collecting the output of one test to have it together
52 CURRENTTRAP
="rm -f \"$OUTPUT\"; $CURRENTTRAP"
53 trap "$CURRENTTRAP" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
55 if [ "$MSGLEVEL" -le 1 ]; then
56 printf "${TESTTORUN##*/}"
57 elif [ "$MSGLEVEL" -le 2 ]; then
58 printf "${CTEST}Testcase ${CHIGH}${TESTTORUN##*/}${CRESET}: "
60 printf "${CTEST}Run Testcase ${CHIGH}${TESTTORUN##*/}${CRESET}\n"
62 if ! "$TESTTORUN"; then
64 if [ "$MSGLEVEL" -le 2 ]; then
65 printf >&2 "\n${CHIGH}Running ${TESTTORUN##*/} -> FAILED${CRESET}\n"
66 elif [ "$MSGLEVEL" -le 2 ]; then
67 printf >&2 "\n${CHIGH}Running ${TESTTORUN##*/} -> FAILED${CRESET}"
69 echo >&2 "${CHIGH}Running ${TESTTORUN##*/} -> FAILED${CRESET}"
72 if [ "$MSGLEVEL" -le 1 ]; then
76 if [ "$MSGLEVEL" -le 1 ]; then
78 elif [ "$MSGLEVEL" -le 2 ]; then
82 # without we end up getting stepped output 'randomly'
86 if [ "$FAIL" = 'yes' ]; then
97 DIR
="$(readlink -f "$(dirname "$0")")"
99 TESTLIST="$(find . -mindepth 1 -maxdepth 1 -regex '^\./test-[^/]*$' | sort)"
100 if [ -n "$APT_TEST_JOBS" ]; then
101 if [ "$MSGCOLOR" != 'NO' ]; then
102 export MSGCOLOR='ALWAYS'
105 if command -v moreutils-parallel >/dev/null 2>&1; then
106 parallel=moreutils-parallel
108 exec $parallel -j "$APT_TEST_JOBS" ".
/$(basename "$0")" -- $(echo "$TESTLIST")
110 TOTAL="$(echo "$TESTLIST" | wc -l)"
111 if [ "$MSGLEVEL" -le 1 ]; then
112 printf "${CTEST}Running testcases
${CRESET}: "
114 for testcase in $TESTLIST; do
115 if [ "$MSGLEVEL" -le 1 ]; then
116 printf "${testcase##*/}"
117 elif [ "$MSGLEVEL" -le 2 ]; then
118 printf "($(($ALL+1))/${TOTAL}) ${CTEST}Testcase
${CHIGH}${testcase##*/}${CRESET}: "
120 printf "${CTEST}Run Testcase
($(($ALL+1))/${TOTAL}) ${CHIGH}${testcase##*/}${CRESET}\n"
122 if ! ${testcase}; then
124 FAILED_TESTS="$FAILED_TESTS ${testcase##*/}"
125 if [ "$MSGLEVEL" -le 1 ]; then
126 printf >&2 "\n${CHIGH}Running
${testcase##*/} -> FAILED
${CRESET}\n"
127 elif [ "$MSGLEVEL" -le 2 ]; then
128 printf >&2 "\n${CHIGH}Running
${testcase##*/} -> FAILED
${CRESET}"
130 echo >&2 "${CHIGH}Running
${testcase##*/} -> FAILED
${CRESET}"
134 if [ "$MSGLEVEL" -le 1 ]; then
139 if [ "$MSGLEVEL" -le 1 ]; then
141 elif [ "$MSGLEVEL" -le 2 ]; then
146 echo >&2 "Statistics
: $ALL tests were run
: $PASS successfully and
$FAIL failed
"
147 if [ -n "$FAILED_TESTS" ]; then
148 echo >&2 "Failed tests
: $FAILED_TESTS"
150 echo >&2 'All tests seem to have been run successfully. What could possibly go wrong?'
152 # ensure we don't overflow
153 exit $((FAIL <= 255 ? FAIL : 255))