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