telegram-bot-bash/test/ALL-tests.inc.sh

71 lines
1.7 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
2020-06-12 09:11:17 +00:00
#### $$VERSION$$ v0.96-0-g3871ca9
# common variables
export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME
TESTME="$(basename "$0")"
DIRME="$(pwd)"
TESTDIR="$1"
LOGFILE="${TESTDIR}/${TESTME}.log"
REFDIR="${TESTME%.sh}"
TESTNAME="${REFDIR//-/ }"
# common filenames
export TOKENFILE ACLFILE COUNTFILE BLOCKEDFILE ADMINFILE DATADIR JSONSHFILE
TOKENFILE="token"
ACLFILE="botacl"
COUNTFILE="count.jssh"
BLOCKEDFILE="blocked.jssh"
ADMINFILE="botadmin"
DATADIR="data-bot-bash"
JSONSHFILE="JSON.sh/JSON.sh"
# SUCCESS NOSUCCES
export SUCCESS NOSUCCESS
2019-04-22 08:19:16 +00:00
SUCCESS=" OK"
NOSUCCESS=" FAILED!"
2019-04-21 12:52:55 +00:00
# default input, reference and output files
2019-04-22 18:34:43 +00:00
export INPUTFILE REFFILE OUTPUTFILE
2019-04-22 08:19:16 +00:00
INPUTFILE="${DIRME}/${REFDIR}/${REFDIR}.input"
REFFILE="${DIRME}/${REFDIR}/${REFDIR}.result"
OUTPUTFILE="${TESTDIR}/${REFDIR}.out"
2019-04-21 12:52:55 +00:00
2019-05-24 08:47:27 +00:00
# do not query telegram when testing
export BASHBOT_URL TESTTOKEN
2019-05-24 08:47:27 +00:00
BASHBOT_URL="https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?"
TESTTOKEN="123456789:BASHBOTTESTSCRIPTbashbottestscript_"
2019-05-24 08:47:27 +00:00
2019-04-21 12:52:55 +00:00
# print arrays in reproducible order
print_array() {
local idx t
local arrays=( "${@}" )
for idx in "${arrays[@]}"; do
declare -n temp="$idx"
for t in "${!temp[@]}"; do
2019-04-22 18:34:43 +00:00
printf '%s:\t%s\t%s\n' "$idx" "$t" "${temp[$t]}"
2019-04-21 12:52:55 +00:00
done | sort
done | grep -v '^USER: 0'
}
2020-06-10 16:07:12 +00:00
compare_sorted() {
local ret=0
sort -d -o "${1}.sort" "${1}"
sort -d -o "${2}.sort" "${2}"
diff -c "${1}.sort" "${2}.sort" || ret=1
rm -f "${1}.sort" "${2}.sort"
return "$ret"
}
2019-04-21 12:52:55 +00:00
######
# lets go ...
echo "Running ${TESTNAME#? } ..."
echo "............................"
[ "${TESTDIR}" = "" ] && echo "${NOSUCCESS} not called from testsuite, exit" && exit 1
# reset env for test
2019-05-26 19:25:01 +00:00
unset IFS;
export TERM=""