]> git.saurik.com Git - apt.git/blame - test/integration/run-tests
correct cross & disappear progress detection
[apt.git] / test / integration / run-tests
CommitLineData
8d876415
DK
1#!/bin/sh
2set -e
3
61e92778 4TESTTORUN=''
1290422a
DK
5while [ -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
31done
32export MSGLEVEL="${MSGLEVEL:-3}"
682a3bf7 33
61e92778 34if [ "${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
38fi
39if [ "$MSGCOLOR" != 'NO' ]; then
682a3bf7
DK
40 CTEST='\033[1;32m'
41 CHIGH='\033[1;35m'
42 CRESET='\033[0m'
1290422a
DK
43else
44 CTEST=''
45 CHIGH=''
46 CRESET=''
fe268128
DK
47fi
48
61e92778
DK
49if [ -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
91fi
92
93FAIL=0
94PASS=0
95ALL=0
96FAILED_TESTS=""
97DIR="$(readlink -f "$(dirname "$0")")"
3abb6a6a
DK
98cd "$DIR"
99TESTLIST="$(find . -mindepth 1 -maxdepth 1 -regex '^\./test-[^/]*$' | sort)"
61e92778
DK
100if [ -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
109fi
110TOTAL="$(echo "$TESTLIST" | wc -l)"
30ea7a60
JAK
111if [ "$MSGLEVEL" -le 1 ]; then
112 printf "${CTEST}Running testcases${CRESET}: "
113fi
61e92778 114for 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 144done
adee3bae 145
0954c58e
DK
146echo >&2 "Statistics: $ALL tests were run: $PASS successfully and $FAIL failed"
147if [ -n "$FAILED_TESTS" ]; then
148 echo >&2 "Failed tests: $FAILED_TESTS"
149else
150 echo >&2 'All tests seem to have been run successfully. What could possibly go wrong?'
2b4e2e83 151fi
f91bd741
MV
152# ensure we don't overflow
153exit $((FAIL <= 255 ? FAIL : 255))