]>
Commit | Line | Data |
---|---|---|
8d876415 DK |
1 | #!/bin/sh |
2 | set -e | |
3 | ||
61e92778 | 4 | TESTTORUN='' |
1290422a DK |
5 | while [ -n "$1" ]; do |
6 | if [ "$1" = "-q" ]; then | |
7 | export MSGLEVEL=2 | |
8 | elif [ "$1" = "-v" ]; then | |
9 | export MSGLEVEL=4 | |
10 | elif [ "$1" = '--color=no' ]; then | |
11 | export MSGCOLOR='NO' | |
61e92778 DK |
12 | elif [ "$1" = '--color=yes' ]; then |
13 | export MSGCOLOR='YES' | |
14 | elif [ "$1" = '--color' ]; then | |
15 | export MSGCOLOR="$(echo "$2" | tr 'a-z' 'A-Z')" | |
16 | shift | |
17 | elif [ "$1" = '--level' ]; then | |
18 | export MSGLEVEL=$2 | |
19 | shift | |
20 | elif [ "$1" = '-j' ]; then | |
21 | APT_TEST_JOBS=$2 | |
22 | shift | |
23 | elif [ -x "$1" ]; then | |
24 | TESTTORUN="$1" | |
1290422a DK |
25 | else |
26 | echo >&2 "WARNING: Unknown parameter »$1« will be ignored" | |
27 | fi | |
28 | shift | |
29 | done | |
30 | export MSGLEVEL="${MSGLEVEL:-3}" | |
682a3bf7 | 31 | |
61e92778 | 32 | if [ "${MSGCOLOR:-YES}" = 'YES' ]; then |
27cb4f6c | 33 | if [ ! -t 1 ]; then # but check that we output to a terminal |
1290422a DK |
34 | export MSGCOLOR='NO' |
35 | fi | |
36 | fi | |
37 | if [ "$MSGCOLOR" != 'NO' ]; then | |
682a3bf7 DK |
38 | CTEST='\033[1;32m' |
39 | CHIGH='\033[1;35m' | |
40 | CRESET='\033[0m' | |
1290422a DK |
41 | else |
42 | CTEST='' | |
43 | CHIGH='' | |
44 | CRESET='' | |
fe268128 DK |
45 | fi |
46 | ||
61e92778 DK |
47 | if [ -n "$TESTTORUN" ]; then |
48 | # collecting the output of one test to have it together | |
49 | OUTPUT="$(mktemp)" | |
3685f84d DK |
50 | CURRENTTRAP="rm -f \"$OUTPUT\"; $CURRENTTRAP" |
51 | trap "$CURRENTTRAP" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM | |
61e92778 DK |
52 | { |
53 | if [ "$MSGLEVEL" -le 2 ]; then | |
54 | printf "${CTEST}Testcase ${CHIGH}${TESTTORUN##*/}${CRESET}: " | |
55 | else | |
56 | printf "${CTEST}Run Testcase ${CHIGH}${TESTTORUN##*/}${CRESET}\n" | |
57 | fi | |
58 | if ! "$TESTTORUN"; then | |
59 | FAIL='yes' | |
60 | if [ "$MSGLEVEL" -le 2 ]; then | |
61 | printf >&2 "\n${CHIGH}Running ${TESTTORUN##*/} -> FAILED${CRESET}" | |
62 | else | |
63 | echo >&2 "${CHIGH}Running ${TESTTORUN##*/} -> FAILED${CRESET}" | |
64 | fi | |
65 | fi | |
66 | if [ "$MSGLEVEL" -le 2 ]; then | |
67 | echo | |
68 | fi | |
69 | } >"$OUTPUT" 2>&1 | |
70 | # without we end up getting stepped output 'randomly' | |
71 | stty sane | |
72 | cat >&2 "$OUTPUT" | |
73 | stty sane | |
74 | if [ "$FAIL" = 'yes' ]; then | |
75 | exit 1 | |
76 | else | |
77 | exit 0 | |
78 | fi | |
79 | fi | |
80 | ||
81 | FAIL=0 | |
82 | PASS=0 | |
83 | ALL=0 | |
84 | FAILED_TESTS="" | |
85 | DIR="$(readlink -f "$(dirname "$0")")" | |
3abb6a6a DK |
86 | cd "$DIR" |
87 | TESTLIST="$(find . -mindepth 1 -maxdepth 1 -regex '^\./test-[^/]*$' | sort)" | |
61e92778 DK |
88 | if [ -n "$APT_TEST_JOBS" ]; then |
89 | if [ "$MSGCOLOR" != 'NO' ]; then | |
90 | export MSGCOLOR='ALWAYS' | |
91 | fi | |
92 | exec parallel -j "$APT_TEST_JOBS" "$0" -- $(echo "$TESTLIST") | |
93 | fi | |
94 | TOTAL="$(echo "$TESTLIST" | wc -l)" | |
95 | for testcase in $TESTLIST; do | |
682a3bf7 | 96 | if [ "$MSGLEVEL" -le 2 ]; then |
61e92778 | 97 | printf "($(($ALL+1))/${TOTAL}) ${CTEST}Testcase ${CHIGH}${testcase##*/}${CRESET}: " |
39cc8228 | 98 | else |
61e92778 | 99 | printf "${CTEST}Run Testcase ($(($ALL+1))/${TOTAL}) ${CHIGH}${testcase##*/}${CRESET}\n" |
39cc8228 | 100 | fi |
adee3bae | 101 | if ! ${testcase}; then |
0954c58e | 102 | FAIL=$((FAIL+1)) |
61e92778 | 103 | FAILED_TESTS="$FAILED_TESTS ${testcase##*/}" |
e52aad52 | 104 | if [ "$MSGLEVEL" -le 2 ]; then |
61e92778 | 105 | printf >&2 "\n${CHIGH}Running ${testcase##*/} -> FAILED${CRESET}" |
e52aad52 | 106 | else |
61e92778 | 107 | echo >&2 "${CHIGH}Running ${testcase##*/} -> FAILED${CRESET}" |
e52aad52 | 108 | fi |
0954c58e DK |
109 | else |
110 | PASS=$((PASS+1)) | |
111 | fi | |
112 | ALL=$((ALL+1)) | |
682a3bf7 | 113 | if [ "$MSGLEVEL" -le 2 ]; then |
39cc8228 DK |
114 | echo |
115 | fi | |
8d876415 | 116 | done |
adee3bae | 117 | |
0954c58e DK |
118 | echo >&2 "Statistics: $ALL tests were run: $PASS successfully and $FAIL failed" |
119 | if [ -n "$FAILED_TESTS" ]; then | |
120 | echo >&2 "Failed tests: $FAILED_TESTS" | |
121 | else | |
122 | echo >&2 'All tests seem to have been run successfully. What could possibly go wrong?' | |
2b4e2e83 | 123 | fi |
f91bd741 MV |
124 | # ensure we don't overflow |
125 | exit $((FAIL <= 255 ? FAIL : 255)) |