From d947c22d4e849d5f936577072769e202efd9f687 Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Mon, 20 May 2024 12:59:06 +0200 Subject: [PATCH 1/4] Remove set -e and add to the end FAILED message in case of test failed. Signed-off-by: Petr "Stone" Hracek --- test.sh | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/test.sh b/test.sh index 2a199cb..b974d7d 100755 --- a/test.sh +++ b/test.sh @@ -6,12 +6,28 @@ # TEST_OPENSHIFT_MODE - If set, run OpenShift tests (if present) # VERSIONS - Must be set to a list with possible versions (subdirectories) -set -eE +set -E trap 'echo "errexit on line $LINENO, $0" >&2' ERR [ -n "${DEBUG:-}" ] && set -x +FAILED_VERSIONS="" + +# failed_version +# ----------------------------- +# Check if testcase ended in error and update FAILED_VERSIONS variable +# Argument: result - testcase result value +# version - version that failed +failed_version() { + local result="$1" + local version="$2" + if [[ "$result" != "0" ]]; then + FAILED_VERSIONS="${FAILED_VERSIONS} ${version}" + fi + return "$result" +} + # This adds backwards compatibility if only single version needs to be testing # In CI we would like to test single version but VERSIONS= means, that nothing is tested # make test TARGET= VERSIONS= ... checks single version for CLI @@ -36,6 +52,7 @@ for dir in ${VERSIONS}; do if [ -n "${TEST_MODE}" ]; then VERSION=$dir test/run + failed_version "$?" "$dir" fi if [ -n "${TEST_OPENSHIFT_4}" ]; then @@ -46,6 +63,7 @@ for dir in ${VERSIONS}; do else if [[ -x test/run-openshift-remote-cluster ]]; then VERSION=$dir test/run-openshift-remote-cluster + failed_version "$?" "$dir" else echo "-> Tests for OpenShift 4 are not present. Add run-openshift-remote-cluster script, skipping" fi @@ -56,9 +74,16 @@ for dir in ${VERSIONS}; do if [ -n "${TEST_UPSTREAM}" ]; then if [[ -x test/run-upstream ]]; then VERSION=$dir test/run-upstream + failed_version "$?" "$dir" else echo "-> Upstream tests are not present, skipping" fi fi popd > /dev/null done + +if [[ "$FAILED_VERSIONS" != "" ]]; then + echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + echo "Test for image ${IMAGE_NAME} FAILED in these versions ${FAILED_VERSIONS}." + echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" +fi From 636799a99903d8ec963891a51b65d624e49fe2e1 Mon Sep 17 00:00:00 2001 From: Petr Hracek Date: Mon, 20 May 2024 14:02:03 +0200 Subject: [PATCH 2/4] Fix conditions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Zuzana Miklánková --- test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.sh b/test.sh index b974d7d..7d864cd 100755 --- a/test.sh +++ b/test.sh @@ -82,7 +82,7 @@ for dir in ${VERSIONS}; do popd > /dev/null done -if [[ "$FAILED_VERSIONS" != "" ]]; then +if [[ -n "$FAILED_VERSIONS" ]]; then echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "Test for image ${IMAGE_NAME} FAILED in these versions ${FAILED_VERSIONS}." echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" From fee1f6a17fc7867f6d7e9fb3d3e36c2cf1340edc Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Mon, 20 May 2024 14:02:50 +0200 Subject: [PATCH 3/4] Remove set -E at all and exit with 1 in case of tests failed Signed-off-by: Petr "Stone" Hracek --- test.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test.sh b/test.sh index 7d864cd..c314e25 100755 --- a/test.sh +++ b/test.sh @@ -6,8 +6,6 @@ # TEST_OPENSHIFT_MODE - If set, run OpenShift tests (if present) # VERSIONS - Must be set to a list with possible versions (subdirectories) -set -E - trap 'echo "errexit on line $LINENO, $0" >&2' ERR [ -n "${DEBUG:-}" ] && set -x @@ -37,7 +35,7 @@ echo "Tested versions are: $VERSIONS" for dir in ${VERSIONS}; do [ ! -e "${dir}/.image-id" ] && echo "-> Image for version $dir not built, skipping tests." && continue - pushd "${dir}" > /dev/null + pushd "${dir}" > /dev/null || exit 1 IMAGE_ID=$(cat .image-id) export IMAGE_ID IMAGE_VERSION=$(docker inspect -f "{{.Config.Labels.version}}" "$IMAGE_ID") @@ -79,11 +77,12 @@ for dir in ${VERSIONS}; do echo "-> Upstream tests are not present, skipping" fi fi - popd > /dev/null + popd > /dev/null || exit 1 done if [[ -n "$FAILED_VERSIONS" ]]; then echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "Test for image ${IMAGE_NAME} FAILED in these versions ${FAILED_VERSIONS}." echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + exit 1 fi From 2229acbe720e89bae02bb70256af4efca888e5d7 Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Tue, 21 May 2024 11:20:43 +0200 Subject: [PATCH 4/4] Get rid off trap that I have missed. Signed-off-by: Petr "Stone" Hracek --- test.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/test.sh b/test.sh index c314e25..39a3379 100755 --- a/test.sh +++ b/test.sh @@ -6,8 +6,6 @@ # TEST_OPENSHIFT_MODE - If set, run OpenShift tests (if present) # VERSIONS - Must be set to a list with possible versions (subdirectories) -trap 'echo "errexit on line $LINENO, $0" >&2' ERR - [ -n "${DEBUG:-}" ] && set -x FAILED_VERSIONS=""