From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 206C46DE10A4 for ; Tue, 4 Jun 2019 12:46:35 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.222 X-Spam-Level: X-Spam-Status: No, score=0.222 tagged_above=-999 required=5 tests=[AWL=-0.027, HEADER_FROM_DIFFERENT_DOMAINS=0.249] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5AztQd0Nqyhd for ; Tue, 4 Jun 2019 12:46:32 -0700 (PDT) Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) by arlo.cworth.org (Postfix) with ESMTP id C28346DE108F for ; Tue, 4 Jun 2019 12:46:31 -0700 (PDT) Received: by guru.guru-group.fi (Postfix, from userid 501) id 21A3D1001E8; Tue, 4 Jun 2019 22:46:26 +0300 (EEST) From: Tomi Ollila To: notmuch@notmuchmail.org Cc: tomi.ollila@iki.fi Subject: [PATCH] test: aggregate-results.sh: consistent style. zero forks. Date: Tue, 4 Jun 2019 22:46:24 +0300 Message-Id: <20190604194624.15102-1-tomi.ollila@iki.fi> X-Mailer: git-send-email 2.13.3 X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Jun 2019 19:46:35 -0000 - 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. --- I have some other changes planned for this -- before that I wanted to clead some accumulated inconsistencies... 2 changes I wanted but did not do: 1) #!/bin/sh 2) set -euf test/aggregate-results.sh | 92 +++++++++++++++------------------------ 1 file changed, 36 insertions(+), 56 deletions(-) diff --git a/test/aggregate-results.sh b/test/aggregate-results.sh index 63228546..0f94948b 100755 --- a/test/aggregate-results.sh +++ b/test/aggregate-results.sh @@ -13,81 +13,61 @@ do while read type value do case $type in - '') - continue ;; fixed) - fixed=$(($fixed + $value)) ;; + fixed=$((fixed + value)) ;; success) - success=$(($success + $value)) ;; + success=$((success + value)) ;; failed) - failed=$(($failed + $value)) ;; + failed=$((failed + value)) ;; broken) - broken=$(($broken + $value)) ;; + broken=$((broken + value)) ;; total) - total=$(($total + $value)) ;; + 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 -} +pluralize_s () { [ $1 -eq 1 ] && s='' || s='s'; } 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; + +if [ $fixed -eq 0 ] && [ $failed -eq 0 ]; then + pluralize_s $total + printf "All $total test$s " + if [ $broken -eq 0 ]; then + echo "passed." + else + pluralize_s $broken + echo "behaved as expected ($broken expected failure$s)." + 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 + echo "$success/$total tests passed." + if [ $broken -ne 0 ]; then + pluralize_s $broken + echo "$broken broken test$s failed as expected." + fi + if [ $fixed -ne 0 ]; then + pluralize_s $fixed + echo "$fixed broken test$s now fixed." + fi + if [ $failed -ne 0 ]; then + pluralize_s $failed + echo "$failed test$s failed." + fi fi -skipped=$(($total - $fixed - $success - $failed - $broken)) -if [ "$skipped" != "0" ]; then - tests=$(pluralize "test" $skipped) - echo "$skipped $tests skipped." +skipped=$((total - fixed - success - failed - broken)) +if [ $skipped -ne 0 ]; then + pluralize_s $skipped + echo "$skipped test$s skipped." fi # Note that we currently do not consider skipped tests as failing the # build. -if [ $success -gt 0 -a $fixed -eq 0 -a $failed -eq 0 ] +if [ $success -gt 0 ] && [ $fixed -eq 0 ] && [ $failed -eq 0 ] then - exit 0 + exit 0 else - exit 1 + exit 1 fi -- 2.21.0