telegram-bot-bash/dev/all-tests.sh

80 lines
1.9 KiB
Bash
Raw Normal View History

2019-04-19 15:31:01 +00:00
#!/usr/bin/env bash
#############################################################
#
# File: dev/all-tests.sh
#
# Description: run all tests, exit after failed test
#
2022-06-27 18:18:58 +00:00
#### $$VERSION$$ v1.52-1-g0dae2db
#############################################################
2019-04-19 15:31:01 +00:00
2021-01-15 13:06:10 +00:00
#shellcheck disable=SC1090
source "${0%/*}/dev.inc.sh"
2019-04-19 15:31:01 +00:00
##########################
2019-04-19 15:31:01 +00:00
# create test environment
TESTENV="/tmp/bashbot.test$$"
2019-04-22 08:19:16 +00:00
mkdir "${TESTENV}"
2019-04-22 18:34:43 +00:00
cp -r ./* "${TESTENV}"
2019-04-20 19:09:36 +00:00
cd "test" || exit 1
2019-04-20 14:26:16 +00:00
2020-12-04 20:35:21 +00:00
# delete possible config
rm -f "${TESTENV}/botconfig.jssh" "${TESTENV}/botacl" 2>/dev/null
2020-12-04 20:35:21 +00:00
# mkdir needed dirs
mkdir "${TESTENV}/data-bot-bash"
# inject JSON.sh
mkdir "${TESTENV}/JSON.sh"
curl -sL "https://cdn.jsdelivr.net/gh/dominictarr/JSON.sh/JSON.sh" >"${TESTENV}/JSON.sh/JSON.sh"
chmod +x "${TESTENV}/JSON.sh/JSON.sh"
########################
#prepare and run tests
2019-04-19 15:31:01 +00:00
#set -e
fail=0
tests=0
passed=0
#all_tests=${__dirname:}
2021-01-01 10:27:54 +00:00
#printf PLAN ${#all_tests}
2019-04-22 18:34:43 +00:00
for test in $(find ./*-test.sh | sort -u) ;
2019-04-19 15:31:01 +00:00
do
[ "${test}" = "dev/all-tests.sh" ] && continue
2019-04-19 15:31:01 +00:00
[ ! -x "${test}" ] && continue
tests=$((tests+1))
2021-01-01 10:27:54 +00:00
printf "TEST: %s\n" "${test}"
2019-04-19 15:31:01 +00:00
"${test}" "${TESTENV}"
ret=$?
2021-01-03 11:06:39 +00:00
set +e
2021-01-05 10:40:28 +00:00
if [ "${ret}" -eq 0 ] ; then
2021-01-01 10:27:54 +00:00
printf "OK: ---- %s\n" "${test}"
2019-04-19 15:31:01 +00:00
passed=$((passed+1))
else
2021-01-01 10:27:54 +00:00
printf "FAIL: %s\n" "${test} ${fail}"
2019-04-19 15:31:01 +00:00
fail=$((fail+ret))
break
fi
done
###########################
# cleanup depending on test state
2021-01-05 10:40:28 +00:00
if [ "${fail}" -eq 0 ]; then
2021-01-01 10:27:54 +00:00
printf 'SUCCESS '
2019-04-19 15:31:01 +00:00
exitcode=0
2020-08-05 05:41:49 +00:00
rm -rf "${TESTENV}"
2019-04-19 15:31:01 +00:00
else
2021-01-01 10:27:54 +00:00
printf 'FAILURE '
2019-04-19 15:31:01 +00:00
exitcode=1
2020-12-31 21:56:58 +00:00
rm -rf "${TESTENV}/test"
find "${TESTENV}/"* ! -name '[a-z]-*' -delete
2019-04-19 15:31:01 +00:00
fi
#########################
# show test result and test logs
2021-01-01 10:27:54 +00:00
printf "%s\n\n" "${passed} / ${tests}"
[ -d "${TESTENV}" ] && printf "Logfiles from run are in %s\n" "${TESTENV}"
2019-04-26 13:07:07 +00:00
2021-01-01 10:27:54 +00:00
ls -ld /tmp/bashbot.test* 2>/dev/null && printf "Do not forget to delete bashbot test files in /tmp!!\n"
2019-04-26 13:07:07 +00:00
2021-01-05 10:40:28 +00:00
exit "${exitcode}"