test: aggregate-results.sh: consistent style. zero forks.

- all variables in $((...)) without leading $
- all comparisons use -gt, -eq or -ne
- no -a nor -o inside [ ... ] expressions
- all indentation levels using one tab

Dropped unnecessary empty string check when reading results files.

Replaced pluralize() which was executed in subshell with
pluralize_s(). pluralize_s sets $s to 's' or '' based on value of
$1. Calls to pluralize_s are done in context of current shell, so
no forks to subshells executed.
This commit is contained in:
Tomi Ollila 2019-06-10 21:39:23 +03:00 committed by David Bremner
parent bc396c967c
commit 00c63bf736

View file

@ -13,81 +13,61 @@ do
while read type value while read type value
do do
case $type in case $type in
'')
continue ;;
fixed) fixed)
fixed=$(($fixed + $value)) ;; fixed=$((fixed + value)) ;;
success) success)
success=$(($success + $value)) ;; success=$((success + value)) ;;
failed) failed)
failed=$(($failed + $value)) ;; failed=$((failed + value)) ;;
broken) broken)
broken=$(($broken + $value)) ;; broken=$((broken + value)) ;;
total) total)
total=$(($total + $value)) ;; total=$((total + value)) ;;
esac esac
done <"$file" done <"$file"
done done
pluralize () { pluralize_s () { [ "$1" -eq 1 ] && s='' || s='s'; }
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." echo "Notmuch test suite complete."
if [ "$fixed" = "0" ] && [ "$failed" = "0" ]; then
tests=$(pluralize "test" $total) if [ "$fixed" -eq 0 ] && [ "$failed" -eq 0 ]; then
printf "All $total $tests " pluralize_s "$total"
if [ "$broken" = "0" ]; then printf "All $total test$s "
echo "passed." if [ "$broken" -eq 0 ]; then
else echo "passed."
failures=$(pluralize "failure" $broken) else
echo "behaved as expected ($broken expected $failures)." pluralize_s "$broken"
fi; echo "behaved as expected ($broken expected failure$s)."
fi
else else
echo "$success/$total tests passed." echo "$success/$total tests passed."
if [ "$broken" != "0" ]; then if [ "$broken" -ne 0 ]; then
tests=$(pluralize "test" $broken) pluralize_s "$broken"
echo "$broken broken $tests failed as expected." echo "$broken broken test$s failed as expected."
fi fi
if [ "$fixed" != "0" ]; then if [ "$fixed" -ne 0 ]; then
tests=$(pluralize "test" $fixed) pluralize_s "$fixed"
echo "$fixed broken $tests now fixed." echo "$fixed broken test$s now fixed."
fi fi
if [ "$failed" != "0" ]; then if [ "$failed" -ne 0 ]; then
tests=$(pluralize "test" $failed) pluralize_s "$failed"
echo "$failed $tests failed." echo "$failed test$s failed."
fi fi
fi fi
skipped=$(($total - $fixed - $success - $failed - $broken)) skipped=$((total - fixed - success - failed - broken))
if [ "$skipped" != "0" ]; then if [ "$skipped" -ne 0 ]; then
tests=$(pluralize "test" $skipped) pluralize_s "$skipped"
echo "$skipped $tests skipped." echo "$skipped test$s skipped."
fi fi
# Note that we currently do not consider skipped tests as failing the # Note that we currently do not consider skipped tests as failing the
# build. # build.
if [ $success -gt 0 -a $fixed -eq 0 -a $failed -eq 0 ] if [ "$success" -gt 0 ] && [ "$fixed" -eq 0 ] && [ "$failed" -eq 0 ]
then then
exit 0 exit 0
else else
exit 1 exit 1
fi fi