aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/aggregate-results.sh
blob: b016edb9117108523642b17862b20846f4fbc89c (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
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
#!/usr/bin/env bash

set -eu

fixed=0
success=0
failed=0
broken=0
total=0

for file
do
	while read type value
	do
		case $type in
		'')
			continue ;;
		fixed)
			fixed=$(($fixed + $value)) ;;
		success)
			success=$(($success + $value)) ;;
		failed)
			failed=$(($failed + $value)) ;;
		broken)
			broken=$(($broken + $value)) ;;
		total)
			total=$(($total + $value)) ;;
		esac
	done <"$file"
done

pluralize () {
    case $2 in
	1)
	    case $1 in
		test)
		    echo test ;;
		failure)
		    echo failure ;;
	    esac
	    ;;
	*)
	    case $1 in
		test)
		    echo tests ;;
		failure)
		    echo failures ;;
	    esac
	    ;;
    esac
}

echo "Notmuch test suite complete."
if [ "$fixed" = "0" ] && [ "$failed" = "0" ]; then
    tests=$(pluralize "test" $total)
    printf "All $total $tests "
    if [ "$broken" = "0" ]; then
	echo "passed."
    else
	failures=$(pluralize "failure" $broken)
	echo "behaved as expected ($broken expected $failures)."
    fi;
else
    echo "$success/$total tests passed."
    if [ "$broken" != "0" ]; then
	tests=$(pluralize "test" $broken)
	echo "$broken broken $tests failed as expected."
    fi
    if [ "$fixed" != "0" ]; then
	tests=$(pluralize "test" $fixed)
	echo "$fixed broken $tests now fixed."
    fi
    if [ "$failed" != "0" ]; then
	tests=$(pluralize "test" $failed)
	echo "$failed $tests failed."
    fi
fi

skipped=$(($total - $fixed - $success - $failed - $broken))
if [ "$skipped" != "0" ]; then
    tests=$(pluralize "test" $skipped)
    echo "$skipped $tests skipped."
fi

if [ $success -gt 0 -a $fixed -eq 0 -a $failed -eq 0 -a $skipped -eq 0 ]
then
    exit 0
else
    exit 1
fi