]> git.saurik.com Git - apt.git/blob - test/integration/run-tests
warn if clearsigned file has ignored content parts
[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
111 APT_TEST_SIGNINGHOME="$(mktemp --directory --tmpdir 'apt-key-signinghome.XXXXXXXXXX')"
112 removesigninghome() {
113 if [ -z "$APT_TEST_SIGNINGHOME" ]; then return; fi
114 GNUPGHOME="${APT_TEST_SIGNINGHOME}" gpgconf --kill gpg-agent >/dev/null 2>&1 || true
115 rm -rf -- "$APT_TEST_SIGNINGHOME"
116 }
117 trap "removesigninghome; exit 0" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
118 export APT_TEST_SIGNINGHOME
119
120 TOTAL="$(echo "$TESTLIST" | wc -l)"
121 if [ "$MSGLEVEL" -le 1 ]; then
122 printf "${CTEST}Running testcases${CRESET}: "
123 fi
124 for testcase in $TESTLIST; do
125 if [ "$MSGLEVEL" -le 1 ]; then
126 printf "${testcase##*/}"
127 elif [ "$MSGLEVEL" -le 2 ]; then
128 printf "($(($ALL+1))/${TOTAL}) ${CTEST}Testcase ${CHIGH}${testcase##*/}${CRESET}: "
129 else
130 printf "${CTEST}Run Testcase ($(($ALL+1))/${TOTAL}) ${CHIGH}${testcase##*/}${CRESET}\n"
131 fi
132 if ! ${testcase}; then
133 FAIL=$((FAIL+1))
134 FAILED_TESTS="$FAILED_TESTS ${testcase##*/}"
135 if [ "$MSGLEVEL" -le 1 ]; then
136 printf >&2 "\n${CHIGH}Running ${testcase##*/} -> FAILED${CRESET}\n"
137 elif [ "$MSGLEVEL" -le 2 ]; then
138 printf >&2 "\n${CHIGH}Running ${testcase##*/} -> FAILED${CRESET}"
139 else
140 echo >&2 "${CHIGH}Running ${testcase##*/} -> FAILED${CRESET}"
141 fi
142 else
143 PASS=$((PASS+1))
144 if [ "$MSGLEVEL" -le 1 ]; then
145 printf " "
146 fi
147 fi
148 ALL=$((ALL+1))
149 if [ "$MSGLEVEL" -le 1 ]; then
150 :
151 elif [ "$MSGLEVEL" -le 2 ]; then
152 echo
153 fi
154 done
155
156 echo >&2 "Statistics: $ALL tests were run: $PASS successfully and $FAIL failed"
157 if [ -n "$FAILED_TESTS" ]; then
158 echo >&2 "Failed tests: $FAILED_TESTS"
159 else
160 echo >&2 'All tests seem to have been run successfully. What could possibly go wrong?'
161 fi
162 # ensure we don't overflow
163 exit $((FAIL <= 255 ? FAIL : 255))