summaryrefslogtreecommitdiffstats
path: root/ctdb/tests/scripts/run_tests
blob: 8df1aecd257ed60fa123a3d3abda96a47262a792 (plain)
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
#!/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

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

[ $? != 0 ] && usage

eval set -- "$temp"

while true ; do
    case "$1" in
	-x) set -x; shift ;;
	-s) with_summary=true ; shift ;;
	--) shift ; break ;;
	*) usage ;;
    esac
done

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

tests_total=0
tests_passed=0
summary=""

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

for f; do
    [ -x $f ] || fail "test \"$f\" is not executable"
    tests_total=$(($tests_total + 1))
    if ctdb_test_run "$f" ; then
	tests_passed=$(($tests_passed + 1))
	t="PASSED"
    else
	t="FAILED"
    fi
    summary=$(printf "%s\n%-${ww}s%s" "$summary" "$f" "$t")
done

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

test_exit