More robust failure detection for the coverage report generation

The previous implementation was hard to understand and could in principle
fail to notice if there was a test case failure and the writing of the
line "Note: $TOTAL_FAIL failures." failed. KISS.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
diff --git a/tests/scripts/basic-build-test.sh b/tests/scripts/basic-build-test.sh
index aae25fe..b8267ce 100755
--- a/tests/scripts/basic-build-test.sh
+++ b/tests/scripts/basic-build-test.sh
@@ -187,6 +187,11 @@
 echo "Test Report Summary"
 echo
 
+# A failure of the left-hand side of a pipe is ignored (this is a limitation
+# of sh). We'll use the presence of this file as a marker that the generation
+# of the report succeeded.
+rm -f "basic-build-test-$$.ok"
+
 {
 
     cd tests
@@ -298,13 +303,7 @@
     echo "Branches Tested    : $BRANCHES_TESTED of $BRANCHES_TOTAL $BRANCHES_PERCENT%"
     echo
 
-    # If there was a failure, remind the reader here. This also ensures that
-    # the coverage summary ends with a distinctive mark so that this script
-    # knows to exit with a failure status.
-    if [ $TOTAL_FAIL -ne 0 ]; then
-        echo "Note: $TOTAL_FAIL failures."
-    fi
-
+    touch "basic-build-test-$$.ok"
 } | tee coverage-summary.txt
 
 make clean
@@ -313,18 +312,7 @@
     mv "$CONFIG_BAK" "$CONFIG_H"
 fi
 
-# If the coverage summary doesn't end with the expected last two lines
-# ("Branches Tested" and a blank line), either there was an error while
-# creating the coverage summary or the coverage summary reported failures.
-# The script runs under `set -e`, so most failures cause it to abort,
-# but failures on the left-hand side of a pipe are not detected (this is
-# a limitation of sh), so we check that the left-hand side of the pipe
-# succeeded by checking that it took the last action that it was expected
-# to take.
-newline='
-'
-case "$(tail -n2 coverage-summary.txt)" in
-    *"$newline"*) exit 1;; # last line was not blank
-    "Branches Tested"*) :;; # looks good
-    *) exit 1;; # next-to-last line had unexpected content
-esac
+# The file must exist, otherwise it means something went wrong while generating
+# the coverage report. If something did go wrong, rm will complain so this
+# script will exit with a failure status.
+rm "basic-build-test-$$.ok"