]> git.cworth.org Git - notmuch/blob - test/aggregate-results.sh
util/string-util: export skip_space
[notmuch] / test / aggregate-results.sh
1 #!/usr/bin/env bash
2
3 set -eu
4
5 fixed=0
6 success=0
7 failed=0
8 broken=0
9 total=0
10
11 for file
12 do
13         while read type value
14         do
15                 case $type in
16                 '')
17                         continue ;;
18                 fixed)
19                         fixed=$(($fixed + $value)) ;;
20                 success)
21                         success=$(($success + $value)) ;;
22                 failed)
23                         failed=$(($failed + $value)) ;;
24                 broken)
25                         broken=$(($broken + $value)) ;;
26                 total)
27                         total=$(($total + $value)) ;;
28                 esac
29         done <"$file"
30 done
31
32 pluralize () {
33     case $2 in
34         1)
35             case $1 in
36                 test)
37                     echo test ;;
38                 failure)
39                     echo failure ;;
40             esac
41             ;;
42         *)
43             case $1 in
44                 test)
45                     echo tests ;;
46                 failure)
47                     echo failures ;;
48             esac
49             ;;
50     esac
51 }
52
53 echo "Notmuch test suite complete."
54 if [ "$fixed" = "0" ] && [ "$failed" = "0" ]; then
55     tests=$(pluralize "test" $total)
56     printf "All $total $tests "
57     if [ "$broken" = "0" ]; then
58         echo "passed."
59     else
60         failures=$(pluralize "failure" $broken)
61         echo "behaved as expected ($broken expected $failures)."
62     fi;
63 else
64     echo "$success/$total tests passed."
65     if [ "$broken" != "0" ]; then
66         tests=$(pluralize "test" $broken)
67         echo "$broken broken $tests failed as expected."
68     fi
69     if [ "$fixed" != "0" ]; then
70         tests=$(pluralize "test" $fixed)
71         echo "$fixed broken $tests now fixed."
72     fi
73     if [ "$failed" != "0" ]; then
74         tests=$(pluralize "test" $failed)
75         echo "$failed $tests failed."
76     fi
77 fi
78
79 skipped=$(($total - $fixed - $success - $failed - $broken))
80 if [ "$skipped" != "0" ]; then
81     tests=$(pluralize "test" $skipped)
82     echo "$skipped $tests skipped."
83 fi
84
85 # Note that we currently do not consider skipped tests as failing the
86 # build.
87
88 if [ $success -gt 0 -a $fixed -eq 0 -a $failed -eq 0 ]
89 then
90     exit 0
91 else
92     exit 1
93 fi