]> git.saurik.com Git - apt.git/blob - test/integration/run-tests
test-apt-cdrom: Fix for gnupg 2.1.15
[apt.git] / test / integration / run-tests
1 #!/bin/sh
2 set -e
3
4 TESTTORUN=''
5 while [ -n "$1" ]; do
6 if [ "$1" = "-q" ]; then
7 export MSGLEVEL=2
8 elif [ "$1" = "-qq" ]; then
9 export MSGLEVEL=1
10 elif [ "$1" = "-v" ]; then
11 export MSGLEVEL=4
12 elif [ "$1" = '--color=no' ]; then
13 export MSGCOLOR='NO'
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"
27 else
28 echo >&2 "WARNING: Unknown parameter »$1« will be ignored"
29 fi
30 shift
31 done
32 export MSGLEVEL="${MSGLEVEL:-3}"
33
34 if [ "${MSGCOLOR:-YES}" = 'YES' ]; then
35 if [ ! -t 1 ]; then # but check that we output to a terminal
36 export MSGCOLOR='NO'
37 fi
38 fi
39 if [ "$MSGCOLOR" != 'NO' ]; then
40 CTEST='\033[1;32m'
41 CHIGH='\033[1;35m'
42 CRESET='\033[0m'
43 else
44 CTEST=''
45 CHIGH=''
46 CRESET=''
47 fi
48
49 if [ -n "$TESTTORUN" ]; then
50 # collecting the output of one test to have it together
51 OUTPUT="$(mktemp)"
52 CURRENTTRAP="rm -f \"$OUTPUT\"; $CURRENTTRAP"
53 trap "$CURRENTTRAP" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
54 {
55 if [ "$MSGLEVEL" -le 1 ]; then
56 printf "${TESTTORUN##*/}"
57 elif [ "$MSGLEVEL" -le 2 ]; then
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
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}"
68 else
69 echo >&2 "${CHIGH}Running ${TESTTORUN##*/} -> FAILED${CRESET}"
70 fi
71 else
72 if [ "$MSGLEVEL" -le 1 ]; then
73 printf " "
74 fi
75 fi
76 if [ "$MSGLEVEL" -le 1 ]; then
77 :
78 elif [ "$MSGLEVEL" -le 2 ]; then
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")")"
98 cd "$DIR"
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'
103 fi
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")
109 fi
110 TOTAL="$(echo "$TESTLIST" | wc -l)"
111 if [ "$MSGLEVEL" -le 1 ]; then
112 printf "${CTEST}Running testcases${CRESET}: "
113 fi
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}: "
119 else
120 printf "${CTEST}Run Testcase ($(($ALL+1))/${TOTAL}) ${CHIGH}${testcase##*/}${CRESET}\n"
121 fi
122 if ! ${testcase}; then
123 FAIL=$((FAIL+1))
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}"
129 else
130 echo >&2 "${CHIGH}Running ${testcase##*/} -> FAILED${CRESET}"
131 fi
132 else
133 PASS=$((PASS+1))
134 if [ "$MSGLEVEL" -le 1 ]; then
135 printf " "
136 fi
137 fi
138 ALL=$((ALL+1))
139 if [ "$MSGLEVEL" -le 1 ]; then
140 :
141 elif [ "$MSGLEVEL" -le 2 ]; then
142 echo
143 fi
144 done
145
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?'
151 fi
152 # ensure we don't overflow
153 exit $((FAIL <= 255 ? FAIL : 255))