]> git.saurik.com Git - apt.git/blob - test/integration/run-tests
tests: change test-skipping detection for arch-specific pkgs
[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" = "-v" ]; then
9 export MSGLEVEL=4
10 elif [ "$1" = '--color=no' ]; then
11 export MSGCOLOR='NO'
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"
25 else
26 echo >&2 "WARNING: Unknown parameter »$1« will be ignored"
27 fi
28 shift
29 done
30 export MSGLEVEL="${MSGLEVEL:-3}"
31
32 if [ "${MSGCOLOR:-YES}" = 'YES' ]; then
33 if [ ! -t 1 ]; then # but check that we output to a terminal
34 export MSGCOLOR='NO'
35 fi
36 fi
37 if [ "$MSGCOLOR" != 'NO' ]; then
38 CTEST='\033[1;32m'
39 CHIGH='\033[1;35m'
40 CRESET='\033[0m'
41 else
42 CTEST=''
43 CHIGH=''
44 CRESET=''
45 fi
46
47 if [ -n "$TESTTORUN" ]; then
48 # collecting the output of one test to have it together
49 OUTPUT="$(mktemp)"
50 {
51 if [ "$MSGLEVEL" -le 2 ]; then
52 printf "${CTEST}Testcase ${CHIGH}${TESTTORUN##*/}${CRESET}: "
53 else
54 printf "${CTEST}Run Testcase ${CHIGH}${TESTTORUN##*/}${CRESET}\n"
55 fi
56 if ! "$TESTTORUN"; then
57 FAIL='yes'
58 if [ "$MSGLEVEL" -le 2 ]; then
59 printf >&2 "\n${CHIGH}Running ${TESTTORUN##*/} -> FAILED${CRESET}"
60 else
61 echo >&2 "${CHIGH}Running ${TESTTORUN##*/} -> FAILED${CRESET}"
62 fi
63 fi
64 if [ "$MSGLEVEL" -le 2 ]; then
65 echo
66 fi
67 } >"$OUTPUT" 2>&1
68 # without we end up getting stepped output 'randomly'
69 stty sane
70 cat >&2 "$OUTPUT"
71 stty sane
72 if [ "$FAIL" = 'yes' ]; then
73 exit 1
74 else
75 exit 0
76 fi
77 fi
78
79 FAIL=0
80 PASS=0
81 ALL=0
82 FAILED_TESTS=""
83 DIR="$(readlink -f "$(dirname "$0")")"
84 TESTLIST="$(run-parts --list "$DIR" --regex '^test-.*$')"
85 if [ -n "$APT_TEST_JOBS" ]; then
86 if [ "$MSGCOLOR" != 'NO' ]; then
87 export MSGCOLOR='ALWAYS'
88 fi
89 exec parallel -j "$APT_TEST_JOBS" "$0" -- $(echo "$TESTLIST")
90 fi
91 TOTAL="$(echo "$TESTLIST" | wc -l)"
92 for testcase in $TESTLIST; do
93 if [ "$MSGLEVEL" -le 2 ]; then
94 printf "($(($ALL+1))/${TOTAL}) ${CTEST}Testcase ${CHIGH}${testcase##*/}${CRESET}: "
95 else
96 printf "${CTEST}Run Testcase ($(($ALL+1))/${TOTAL}) ${CHIGH}${testcase##*/}${CRESET}\n"
97 fi
98 if ! ${testcase}; then
99 FAIL=$((FAIL+1))
100 FAILED_TESTS="$FAILED_TESTS ${testcase##*/}"
101 if [ "$MSGLEVEL" -le 2 ]; then
102 printf >&2 "\n${CHIGH}Running ${testcase##*/} -> FAILED${CRESET}"
103 else
104 echo >&2 "${CHIGH}Running ${testcase##*/} -> FAILED${CRESET}"
105 fi
106 else
107 PASS=$((PASS+1))
108 fi
109 ALL=$((ALL+1))
110 if [ "$MSGLEVEL" -le 2 ]; then
111 echo
112 fi
113 done
114
115 echo >&2 "Statistics: $ALL tests were run: $PASS successfully and $FAIL failed"
116 if [ -n "$FAILED_TESTS" ]; then
117 echo >&2 "Failed tests: $FAILED_TESTS"
118 else
119 echo >&2 'All tests seem to have been run successfully. What could possibly go wrong?'
120 fi
121 # ensure we don't overflow
122 exit $((FAIL <= 255 ? FAIL : 255))