]> git.saurik.com Git - apt.git/blob - test/integration/run-tests
e90b4b7558eb13c3b45d04cc5b968fb0c6b9575e
[apt.git] / test / integration / run-tests
1 #!/bin/sh
2
3 TESTDIR="$(readlink -f "$(dirname "$0")")"
4 . "$TESTDIR/framework"
5
6 find_project_binary_dir
7
8 set -e
9
10 TESTTORUN=''
11 while [ -n "$1" ]; do
12 if [ "$1" = "-q" ]; then
13 export MSGLEVEL=2
14 elif [ "$1" = "-v" ]; then
15 export MSGLEVEL=4
16 elif [ "$1" = '--color=no' ]; then
17 export MSGCOLOR='NO'
18 elif [ "$1" = '--color=yes' ]; then
19 export MSGCOLOR='YES'
20 elif [ "$1" = '--color' ]; then
21 export MSGCOLOR="$(echo "$2" | tr 'a-z' 'A-Z')"
22 shift
23 elif [ "$1" = '--level' ]; then
24 export MSGLEVEL=$2
25 shift
26 elif [ "$1" = '-j' ]; then
27 APT_TEST_JOBS=$2
28 shift
29 elif [ -x "$1" ]; then
30 TESTTORUN="$1"
31 else
32 echo >&2 "WARNING: Unknown parameter »$1« will be ignored"
33 fi
34 shift
35 done
36 export MSGLEVEL="${MSGLEVEL:-3}"
37
38 if [ "${MSGCOLOR:-YES}" = 'YES' ]; then
39 if [ ! -t 1 ]; then # but check that we output to a terminal
40 export MSGCOLOR='NO'
41 fi
42 fi
43 if [ "$MSGCOLOR" != 'NO' ]; then
44 CTEST='\033[1;32m'
45 CHIGH='\033[1;35m'
46 CRESET='\033[0m'
47 else
48 CTEST=''
49 CHIGH=''
50 CRESET=''
51 fi
52
53 if [ -n "$TESTTORUN" ]; then
54 # collecting the output of one test to have it together
55 OUTPUT="$(mktemp)"
56 CURRENTTRAP="rm -f \"$OUTPUT\"; $CURRENTTRAP"
57 trap "$CURRENTTRAP" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
58 {
59 if [ "$MSGLEVEL" -le 2 ]; then
60 printf "${CTEST}Testcase ${CHIGH}${TESTTORUN##*/}${CRESET}: "
61 else
62 printf "${CTEST}Run Testcase ${CHIGH}${TESTTORUN##*/}${CRESET}\n"
63 fi
64 if ! "$TESTTORUN"; then
65 FAIL='yes'
66 if [ "$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 fi
72 if [ "$MSGLEVEL" -le 2 ]; then
73 echo
74 fi
75 } >"$OUTPUT" 2>&1
76 # without we end up getting stepped output 'randomly'
77 stty sane
78 cat >&2 "$OUTPUT"
79 stty sane
80 if [ "$FAIL" = 'yes' ]; then
81 exit 1
82 else
83 exit 0
84 fi
85 fi
86
87 FAIL=0
88 PASS=0
89 ALL=0
90 FAILED_TESTS=""
91 DIR="$(readlink -f "$(dirname "$0")")"
92 cd "$DIR"
93 TESTLIST="$(find . -mindepth 1 -maxdepth 1 -regex '^\./test-[^/]*$' | sort)"
94 if [ -n "$APT_TEST_JOBS" ]; then
95 if [ "$MSGCOLOR" != 'NO' ]; then
96 export MSGCOLOR='ALWAYS'
97 fi
98 exec parallel -j "$APT_TEST_JOBS" "./$(basename "$0")" -- $(echo "$TESTLIST")
99 fi
100 TOTAL="$(echo "$TESTLIST" | wc -l)"
101 for testcase in $TESTLIST; do
102 if [ "$MSGLEVEL" -le 2 ]; then
103 printf "($(($ALL+1))/${TOTAL}) ${CTEST}Testcase ${CHIGH}${testcase##*/}${CRESET}: "
104 else
105 printf "${CTEST}Run Testcase ($(($ALL+1))/${TOTAL}) ${CHIGH}${testcase##*/}${CRESET}\n"
106 fi
107 if ! ${testcase}; then
108 FAIL=$((FAIL+1))
109 FAILED_TESTS="$FAILED_TESTS ${testcase##*/}"
110 if [ "$MSGLEVEL" -le 2 ]; then
111 printf >&2 "\n${CHIGH}Running ${testcase##*/} -> FAILED${CRESET}"
112 else
113 echo >&2 "${CHIGH}Running ${testcase##*/} -> FAILED${CRESET}"
114 fi
115 else
116 PASS=$((PASS+1))
117 fi
118 ALL=$((ALL+1))
119 if [ "$MSGLEVEL" -le 2 ]; then
120 echo
121 fi
122 done
123
124 echo >&2 "Statistics: $ALL tests were run: $PASS successfully and $FAIL failed"
125 if [ -n "$FAILED_TESTS" ]; then
126 echo >&2 "Failed tests: $FAILED_TESTS"
127 else
128 echo >&2 'All tests seem to have been run successfully. What could possibly go wrong?'
129 fi
130 # ensure we don't overflow
131 exit $((FAIL <= 255 ? FAIL : 255))