diff mbox series

[RFC,v5,02/10] CI: add --exit-code to ci/print-test-failures.sh

Message ID RFC-patch-v5-02.10-caec0b1089a-20220421T183001Z-avarab@gmail.com (mailing list archive)
State New, archived
Headers show
Series CI: js/ci-github-workflow-markup rebased on "use $GITHUB_ENV" | expand

Commit Message

Ævar Arnfjörð Bjarmason April 21, 2022, 6:36 p.m. UTC
The ci/print-test-failures.sh scripts will exit 0 when there's failed
tests, let's teach it --exit-code to have it exit non-zero in those
cases.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 ci/print-test-failures.sh | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
diff mbox series

Patch

diff --git a/ci/print-test-failures.sh b/ci/print-test-failures.sh
index f6736f424e0..d00cd0e4944 100755
--- a/ci/print-test-failures.sh
+++ b/ci/print-test-failures.sh
@@ -8,16 +8,33 @@  set -e
 . ${0%/*}/lib-ci-type.sh
 . ${0%/*}/lib-tput.sh
 
+exit_code=
+while test $# != 0
+do
+	case "$1" in
+	--exit-code)
+		exit_code=t
+		;;
+	*)
+		echo "BUG: invalid $0 argument: $1" >&2
+		exit 1
+		;;
+	esac
+	shift
+done
+
 if ! ls t/test-results/*.exit >/dev/null 2>/dev/null
 then
 	echo "Build job failed before the tests could have been run"
 	exit
 fi
 
+failed=
 for TEST_EXIT in t/test-results/*.exit
 do
 	if [ "$(cat "$TEST_EXIT")" != "0" ]
 	then
+		failed=t
 		TEST_NAME="${TEST_EXIT%.exit}"
 		TEST_NAME="${TEST_NAME##*/}"
 		TEST_OUT="${TEST_NAME}.out"
@@ -42,3 +59,11 @@  do
 		esac
 	fi
 done
+
+if test -n "$failed"
+then
+	if test -n "$exit_code"
+	then
+		exit 1
+	fi
+fi