Fix the run_tests script so that the number of columns is never 0.
[sahlberg/ctdb.git] / tests / scripts / run_tests
1 #!/bin/bash
2
3 # The ability of ctdb_test_env to take tests on the command-line is
4 # nice, but here we need to hack around it with that colon to reset
5 # the arguments that it sees.
6 . $(dirname $0)/ctdb_test_env :
7
8 . ctdb_test_functions.bash
9
10 usage() {
11     cat <<EOF
12 Usage: run_tests [OPTIONS] [TESTS]
13
14 EOF
15     exit 1
16 }
17
18 ######################################################################
19
20 with_summary=false
21
22 temp=$(getopt -n "$prog" -o "xhs" -l help -- "$@")
23
24 [ $? != 0 ] && usage
25
26 eval set -- "$temp"
27
28 while true ; do
29     case "$1" in
30         -x) set -x; shift ;;
31         -s) with_summary=true ; shift ;;
32         --) shift ; break ;;
33         *) usage ;;
34     esac
35 done
36
37 ######################################################################
38
39 tests_total=0
40 tests_passed=0
41 summary=""
42
43 rows=$(if tty -s ; then stty size ; else echo x 80 ; fi | sed -e 's@.* @@' -e 's@^0$@80@')
44 ww=$((rows - 7))
45
46 for f; do
47     [ -x $f ] || fail "test \"$f\" is not executable"
48     tests_total=$(($tests_total + 1))
49     if ctdb_test_run "$f" ; then
50         tests_passed=$(($tests_passed + 1))
51         t="PASSED"
52     else
53         t="FAILED"
54     fi
55     summary=$(printf "%s\n%-${ww}s%s" "$summary" "$f" "$t")
56 done
57
58 if $with_summary ; then
59     echo "$summary"
60     echo
61     echo "${tests_passed}/${tests_total} tests passed"
62 fi
63
64 test_exit