]> git.cworth.org Git - notmuch-old/blob - test/aggregate-results.sh
nmweb: Fix spacing around punctuation in headers
[notmuch-old] / 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 all_skipped=0
11 rep_failed=0
12
13 for file
14 do
15         if [ ! -f "$file" ]; then
16                 echo "'$file' does not exist!"
17                 rep_failed=$((rep_failed + 1))
18                 continue
19         fi
20         has_total=0
21         while read type value
22         do
23                 case $type in
24                 fixed)
25                         fixed=$((fixed + value)) ;;
26                 success)
27                         success=$((success + value)) ;;
28                 failed)
29                         failed=$((failed + value)) ;;
30                 broken)
31                         broken=$((broken + value)) ;;
32                 total)
33                         total=$((total + value))
34                         has_total=1
35                         if [ "$value" -eq 0 ]; then
36                                 all_skipped=$((all_skipped + 1))
37                         fi
38                 esac
39         done <"$file"
40         if [ "$has_total" -eq 0 ]; then
41                 echo "'$file' lacks 'total ...'; results may be inconsistent."
42                 failed=$((failed + 1))
43         fi
44 done
45
46 pluralize_s () { [ "$1" -eq 1 ] && s='' || s='s'; }
47
48 echo "Notmuch test suite complete."
49
50 if [ "$fixed" -eq 0 ] && [ "$failed" -eq 0 ] && [ "$rep_failed" -eq 0 ]; then
51         pluralize_s "$total"
52         printf "All $total test$s "
53         if [ "$broken" -eq 0 ]; then
54                 echo "passed."
55         else
56                 pluralize_s "$broken"
57                 echo "behaved as expected ($broken expected failure$s)."
58         fi
59 else
60         echo "$success/$total tests passed."
61         if [ "$broken" -ne 0 ]; then
62                 pluralize_s "$broken"
63                 echo "$broken broken test$s failed as expected."
64         fi
65         if [ "$fixed" -ne 0 ]; then
66                 pluralize_s "$fixed"
67                 echo "$fixed broken test$s now fixed."
68         fi
69         if [ "$failed" -ne 0 ]; then
70                 pluralize_s "$failed"
71                 echo "$failed test$s failed."
72         fi
73 fi
74
75 skipped=$((total - fixed - success - failed - broken))
76 if [ "$skipped" -ne 0 ]; then
77         pluralize_s "$skipped"
78         echo "$skipped test$s skipped."
79 fi
80 if [ "$all_skipped" -ne 0 ]; then
81         pluralize_s "$all_skipped"
82         echo "All tests in $all_skipped file$s skipped."
83 fi
84
85 if [ "$rep_failed" -ne 0 ]; then
86         pluralize_s "$rep_failed"
87         echo "$rep_failed test$s failed to report results."
88 fi
89
90 # Note that we currently do not consider skipped tests as failing the
91 # build.
92
93 if [ "$success" -gt 0 ] && [ "$fixed" -eq 0 ] &&
94         [ "$failed" -eq 0 ] && [ "$rep_failed" -eq 0 ]
95 then
96         exit 0
97 else
98         exit 1
99 fi