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