improve stdout/stderr usage correctness in test framework
[ntk/apt.git] / test / integration / run-tests
1 #!/bin/sh
2 set -e
3
4 FAIL=0
5 PASS=0
6 ALL=0
7
8 FAILED_TESTS=""
9 DIR=$(readlink -f $(dirname $0))
10 if [ "$1" = "-q" ]; then
11 export MSGLEVEL=2
12 elif [ "$1" = "-v" ]; then
13 export MSGLEVEL=4
14 fi
15
16 if expr match "$(readlink -f /proc/$$/fd/1)" '/dev/pts/[0-9]\+' > /dev/null; then
17 CTEST='\033[1;32m'
18 CHIGH='\033[1;35m'
19 CRESET='\033[0m'
20 elif [ -z "${MSGLEVEL}" ]; then
21 export MSGLEVEL=2
22 fi
23
24 if [ -z "$MSGLEVEL" ]; then
25 MSGLEVEL=5
26 fi
27
28 for testcase in $(run-parts --list $DIR | grep '/test-'); do
29 if [ "$MSGLEVEL" -le 2 ]; then
30 echo -n "${CTEST}Testcase ${CHIGH}$(basename ${testcase})${CRESET}: "
31 else
32 echo "${CTEST}Run Testcase ${CHIGH}$(basename ${testcase})${CRESET}"
33 fi
34 if ! ${testcase}; then
35 FAIL=$((FAIL+1))
36 FAILED_TESTS="$FAILED_TESTS $(basename $testcase)"
37 echo >&2 "$(basename $testcase) ... FAIL"
38 else
39 PASS=$((PASS+1))
40 fi
41 ALL=$((ALL+1))
42 if [ "$MSGLEVEL" -le 2 ]; then
43 echo
44 fi
45 done
46
47 echo >&2 "Statistics: $ALL tests were run: $PASS successfully and $FAIL failed"
48 if [ -n "$FAILED_TESTS" ]; then
49 echo >&2 "Failed tests: $FAILED_TESTS"
50 else
51 echo >&2 'All tests seem to have been run successfully. What could possibly go wrong?'
52 fi
53 # ensure we don't overflow
54 exit $((FAIL <= 255 ? FAIL : 255))