From 1304cf5f02cba9dcf12bec0c62fcfa40eabd0dc2 Mon Sep 17 00:00:00 2001 From: ssube Date: Wed, 30 Oct 2019 18:24:00 -0500 Subject: [PATCH] fix(scripts): make example tests more shell compatible (#106) --- scripts/test-examples.sh | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/scripts/test-examples.sh b/scripts/test-examples.sh index 32b6a5a..d0b4b50 100755 --- a/scripts/test-examples.sh +++ b/scripts/test-examples.sh @@ -1,22 +1,20 @@ -#! /bin/bash - EXAMPLES="$(find ./examples -name '*.yml')" -while read -r example; +for example in ${EXAMPLES}; do echo "Testing: ${example}" USE_RULES="$(grep '# test rules' "${example}" | sed 's/# test rules \(.*\)/\1/')" - [[ -z "${USE_RULES}" ]] && echo "Test example must have '# test rules' pragma" && exit 1 + [ -z "${USE_RULES}" ] && echo "Test example must have '# test rules' pragma" && exit 1 USE_TAGS="$(grep '# test tags' "${example}" | sed 's/# test tags \(.*\)/\1/')" - [[ -z "${USE_TAGS}" ]] && echo "Test example must have '# test tags' pragma" && exit 1 + [ -z "${USE_TAGS}" ] && echo "Test example must have '# test tags' pragma" && exit 1 EXPECTED_ERRORS="$(grep '# test error-count' "${example}" | sed 's/# test error-count \([0-9]*\)/\1/')" - [[ -z "${EXPECTED_ERRORS}" ]] && EXPECTED_ERRORS=0 + [ -z "${EXPECTED_ERRORS}" ] && EXPECTED_ERRORS=0 EXPECTED_STATUS="$(grep '# test exit-status' "${example}" | sed 's/# test exit-status \([0-9]*\)/\1/')" - [[ -z "${EXPECTED_STATUS}" ]] && EXPECTED_STATUS=0 + [ -z "${EXPECTED_STATUS}" ] && EXPECTED_STATUS=0 echo "Using rules: ${USE_RULES}" echo "Using tags: ${USE_TAGS}" @@ -32,11 +30,11 @@ do ACTUAL_STATUS=$? - if [[ "${ACTUAL_STATUS}" != "${EXPECTED_STATUS}" ]]; + if [ "${ACTUAL_STATUS}" != "${EXPECTED_STATUS}" ]; then echo "Exit status does not match! (expected ${EXPECTED_STATUS}, got ${ACTUAL_STATUS})" exit 1 fi -done <<< "${EXAMPLES}" +done echo "All examples passed."