File: run_tests

package info (click to toggle)
ctdb 1.12%2Bgit20120201-5
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 6,656 kB
  • sloc: ansic: 61,736; sh: 18,367; xml: 3,887; python: 1,220; makefile: 554; perl: 319; awk: 118
file content (92 lines) | stat: -rwxr-xr-x 1,710 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash

# The ability of ctdb_test_env to take tests on the command-line is
# nice, but here we need to hack around it with that colon to reset
# the arguments that it sees.
. $(dirname $0)/ctdb_test_env :

. ctdb_test_functions.bash

usage() {
    cat <<EOF
Usage: run_tests [OPTIONS] [TESTS]

EOF
    exit 1
}

######################################################################

with_summary=false
with_desc=false
quiet=false

temp=$(getopt -n "$prog" -o "xdhqs" -l help -- "$@")

[ $? != 0 ] && usage

eval set -- "$temp"

while true ; do
    case "$1" in
	-x) set -x; shift ;;
	-d) with_desc=true ; shift ;;  # 4th line of output is description
	-q) quiet=true ; shift ;;
	-s) with_summary=true ; shift ;;
	--) shift ; break ;;
	*) usage ;;
    esac
done

if $quiet ; then
    show_progress() { cat >/dev/null ; }
else
    show_progress() { cat ; }
fi

######################################################################

tests_total=0
tests_passed=0
summary=""

rows=$(if tty -s ; then stty size ; else echo x 80 ; fi | sed -e 's@.* @@' -e 's@^0$@80@')
ww=$((rows - 7))

tf=$(mktemp)
sf=$(mktemp)

set -o pipefail

for f; do
    [ -x $f ] || fail "test \"$f\" is not executable"
    tests_total=$(($tests_total + 1))
    ctdb_test_run "$f" | tee "$tf" | show_progress
    status=$?
    if $with_summary ; then
	if [ $status -eq 0 ] ; then
	    tests_passed=$(($tests_passed + 1))
	    t=" PASSED "
	else
	    t="*FAILED*"
	fi
	if $with_desc ; then
	    desc=$(tail -n +4 $tf | head -n 1)
	    f="$desc"
	fi
	echo "$t $f" >>"$sf"
    fi
done

rm -f "$tf"

if $with_summary ; then
    echo
    cat "$sf"
    echo
    echo "${tests_passed}/${tests_total} tests passed"
fi

rm -f "$sf"

test_exit