1
0
Fork 0
salty-dog/scripts/test-examples.sh

43 lines
1.2 KiB
Bash
Raw Normal View History

2019-10-31 10:05:15 +00:00
#! /bin/sh
EXAMPLES="$(find ./test/examples -name '*.yml')"
for example in ${EXAMPLES};
do
2019-07-01 13:02:38 +00:00
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
2019-07-01 13:02:38 +00:00
USE_TAGS="$(grep '# test tags' "${example}" | sed 's/# test tags \(.*\)/\1/')"
[ -z "${USE_TAGS}" ] && echo "Test example must have '# test tags' pragma" && exit 1
2019-07-01 13:02:38 +00:00
EXPECTED_STATUS="$(grep '# test exit-status' "${example}" | sed 's/# test exit-status \([0-9]*\)/\1/')"
[ -z "${EXPECTED_STATUS}" ] && EXPECTED_STATUS=0
2019-07-01 13:02:38 +00:00
echo "Using rules: ${USE_RULES}"
echo "Using tags: ${USE_TAGS}"
echo "Expected status: ${EXPECTED_STATUS}"
node out/index.js \
--config-path ./docs \
--config-name config-stderr.yml \
--count \
--rules "rules/${USE_RULES}.yml" \
--tag "${USE_TAGS}" \
--source "${example}"
ACTUAL_STATUS=$?
echo "Actual status: ${ACTUAL_STATUS}"
if [ "${ACTUAL_STATUS}" != "${EXPECTED_STATUS}" ];
then
2019-07-01 13:02:38 +00:00
echo "Exit status does not match! (expected ${EXPECTED_STATUS}, got ${ACTUAL_STATUS})"
echo "Failed in: ${example}"
exit 1
fi
done
echo "All examples passed."