tests: d-inline and d-message printf conversion

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2021-01-02 16:18:15 +01:00
parent 0dfbf7bbac
commit 7e1c1b51e1
3 changed files with 42 additions and 22 deletions

View File

@ -10,7 +10,7 @@
# LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/ # LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/
# AUTHOR: KayM (gnadelwartz), kay@rrr.de # AUTHOR: KayM (gnadelwartz), kay@rrr.de
# #
#### $$VERSION$$ v1.21-pre-35-g32b99dc #### $$VERSION$$ v1.21-pre-36-g0dfbf7b
#=============================================================================== #===============================================================================
# include common functions and definitions # include common functions and definitions
@ -48,7 +48,7 @@ cd "${TESTDIR}" || exit
printf "%s\n" "Test if ${JSONSHFILE} exists ..." printf "%s\n" "Test if ${JSONSHFILE} exists ..."
[ ! -x "$JSONSHFILE" ] && { printf "%s\n" "${NOSUCCESS} json.sh not found"; exit 1; } [ ! -x "$JSONSHFILE" ] && { printf "%s\n" "${NOSUCCESS} json.sh not found"; exit 1; }
printf "Test Sourcing of bashbot.sh ..." printf "Test Sourcing of bashbot.sh ...\n"
# shellcheck source=./bashbot.sh # shellcheck source=./bashbot.sh
source "${TESTDIR}/bashbot.sh" source source "${TESTDIR}/bashbot.sh" source

View File

@ -1,5 +1,17 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#### $$VERSION$$ v1.20-0-g2ab00a2 #===============================================================================
#
# FILE: d-process_inline-test.sh
#
# USAGE: must run only from dev/all-tests.sh
#
# DESCRIPTION: test response to inline messages
#
# LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
#
#### $$VERSION$$ v1.21-pre-36-g0dfbf7b
#===============================================================================
# include common functions and definitions # include common functions and definitions
# shellcheck source=test/ALL-tests.inc.sh # shellcheck source=test/ALL-tests.inc.sh
@ -16,7 +28,7 @@ source "${TESTDIR}/modules/answerInline.sh" source
# overwrite get_file for test # overwrite get_file for test
get_file() { get_file() {
echo "$1" printf "%s\n" "$1"
} }
# get telegram input from file # get telegram input from file
@ -26,19 +38,15 @@ declare -A UPD
source <( printf 'UPD=( %s )' "$(sed <<<"${UPDATE}" -E -e 's/\t/=/g' -e 's/=(true|false)/="\1"/')" ) source <( printf 'UPD=( %s )' "$(sed <<<"${UPDATE}" -E -e 's/\t/=/g' -e 's/=(true|false)/="\1"/')" )
# run process_message with and without python # run process_message with and without python
echo "Check process_inline ..." printf "Check process_inline ...\n"
for i in 1 2 printf " ... with JsonDecode Bash\n"
do set -x
[ "${i}" = "1" ] && ! command -v python >/dev/null 2>&1 && continue { process_inline "0"; set +x; } >>"${LOGFILE}" 2>&1;
[ "${i}" = "1" ] && echo " ... with JsonDecode Python" && unset BASHBOT_DECODE
[ "${i}" = "2" ] && echo " ... with JsonDecode Bash" && export BASHBOT_DECODE="yes"
set -x
{ process_inline "0"; set +x; } >>"${LOGFILE}" 2>&1;
# output processed input # output processed input
print_array "iQUERY" >"${OUTPUTFILE}" print_array "iQUERY" >"${OUTPUTFILE}"
compare_sorted "${REFFILE}" "${OUTPUTFILE}" || exit 1 compare_sorted "${REFFILE}" "${OUTPUTFILE}" || exit 1
echo "${SUCCESS}"
done printf "%s\n" "${SUCCESS}"
cd "${DIRME}" || exit 1 cd "${DIRME}" || exit 1

View File

@ -1,5 +1,17 @@
#!/usr/bin/env bash #!/usr/bin/env bash
#### $$VERSION$$ v1.20-0-g2ab00a2 #===============================================================================
#
# FILE: d-process_message-test.sh
#
# USAGE: must run only from dev/all-tests.sh
#
# DESCRIPTION: test sending messages
#
# LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
#
#### $$VERSION$$ v1.21-pre-36-g0dfbf7b
#===============================================================================
# include common functions and definitions # include common functions and definitions
# shellcheck source=test/ALL-tests.inc.sh # shellcheck source=test/ALL-tests.inc.sh
@ -16,7 +28,7 @@ source "${TESTDIR}/commands.sh" source
# overwrite get_file for test # overwrite get_file for test
get_file() { get_file() {
echo "$1" printf "%s\n" "$1"
} }
# get telegram input from file # get telegram input from file
@ -26,7 +38,7 @@ declare -Ax UPD
# run process_message -------------- # run process_message --------------
ARRAYS="USER CHAT REPLYTO FORWARD URLS CONTACT CAPTION LOCATION MESSAGE VENUE SERVICE NEWMEMBER LEFTMEMBER PINNED" ARRAYS="USER CHAT REPLYTO FORWARD URLS CONTACT CAPTION LOCATION MESSAGE VENUE SERVICE NEWMEMBER LEFTMEMBER PINNED"
echo "Check process_message regular message..." printf "Check process_message regular message...\n"
UPDATE="$(< "${INPUTFILE}")" UPDATE="$(< "${INPUTFILE}")"
Json2Array 'UPD' <"${INPUTFILE}" Json2Array 'UPD' <"${INPUTFILE}"
@ -40,7 +52,7 @@ print_array ${ARRAYS} >"${OUTPUTFILE}"
compare_sorted "${REFFILE}" "${OUTPUTFILE}" || exit 1 compare_sorted "${REFFILE}" "${OUTPUTFILE}" || exit 1
# run process_message ------------ # run process_message ------------
echo "Check process_message service message..." printf "Check process_message service message...\n"
UPDATE="$(cat "${INPUTFILE2}")" UPDATE="$(cat "${INPUTFILE2}")"
Json2Array 'UPD' <"${INPUTFILE2}" Json2Array 'UPD' <"${INPUTFILE2}"
@ -54,6 +66,6 @@ print_array ${ARRAYS} >"${OUTPUTFILE}"
compare_sorted "${REFFILE2}" "${OUTPUTFILE}" || exit 1 compare_sorted "${REFFILE2}" "${OUTPUTFILE}" || exit 1
echo "${SUCCESS}" printf "%s\n" "${SUCCESS}"
cd "${DIRME}" || exit 1 cd "${DIRME}" || exit 1