From d26a992ecbabb9bf3f95b7436292b917e62655db Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Fri, 26 Apr 2019 14:41:49 +0200 Subject: [PATCH] testsuite for send_message, fix 3 found problems --- bashbot.sh | 6 +-- modules/background.sh | 8 +-- test/d-process_message-test.sh | 2 +- test/d-send_message-test.sh | 38 +++++++++++++ .../d-send_message-test.input | 17 ++++++ .../d-send_message-test.result | 54 +++++++++++++++++++ 6 files changed, 117 insertions(+), 8 deletions(-) create mode 100755 test/d-send_message-test.sh create mode 100644 test/d-send_message-test/d-send_message-test.input create mode 100644 test/d-send_message-test/d-send_message-test.result diff --git a/bashbot.sh b/bashbot.sh index fc5cad7..a186c66 100755 --- a/bashbot.sh +++ b/bashbot.sh @@ -12,7 +12,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.70-dev3-12-ga288a8d +#### $$VERSION$$ v0.70-dev3-13-g81b540a # # Exit Codes: # - 0 sucess (hopefully) @@ -420,8 +420,8 @@ send_location() { send_venue() { local add="" [ "$5" = "" ] && return - [ "$6" != "" ] add=', "foursquare_id": '"$6"'' - sendJson "${1}" '"latitude": '"${2}"', "longitude": '"${3}"', "title": "'"${4}"'"'"${add}" "$VENUE_URL" + [ "$6" != "" ] && add=', "foursquare_id": '"$6"'' + sendJson "${1}" '"latitude": '"${2}"', "longitude": '"${3}"', "address": "'"${5}"'", "title": "'"${4}"'"'"${add}" "$VENUE_URL" } diff --git a/modules/background.sh b/modules/background.sh index 89579f4..cc096c5 100644 --- a/modules/background.sh +++ b/modules/background.sh @@ -5,7 +5,7 @@ # This file is public domain in the USA and all free countries. # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # -#### $$VERSION$$ v0.70-dev2-27-g2da31c1 +#### $$VERSION$$ v0.70-dev3-13-g81b540a # source from commands.sh if you want ro use interactive or background jobs @@ -16,7 +16,7 @@ export res # I placed send_message here because main use case is interactive chats and background jobs send_message() { local text arg keyboard file lat long title address sent - [ "$2" = "" ] && return 1 + [ "$2" = "" ] && return local mychat="$1" text="$(echo "$2" | sed 's/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mylongstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')" arg="$3" @@ -32,9 +32,9 @@ send_message() { long="$(echo "$2" | sed '/mylongstartshere /!d;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mytitlestartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')" - title="$(echo "$2" | sed '/mytitlestartshere /!d;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')" + title="$(echo "$2" | sed '/mytitlestartshere /!d;s/.*mytitlestartshere //g;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ myaddressstartshere.*//g;s/ mykeyboardendshere.*//g')" - address="$(echo "$2" | sed '/myaddressstartshere /!d;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mytitlestartshere.*//g;s/ mykeyboardendshere.*//g')" + address="$(echo "$2" | sed '/myaddressstartshere /!d;s/.*myaddressstartshere //g;s/.*mylongstartshere //g;s/ mykeyboardstartshere.*//g;s/ myfilelocationstartshere.*//g;s/ mylatstartshere.*//g;s/ mytitlestartshere.*//g;s/ mykeyboardendshere.*//g')" } if [ "$no_keyboard" != "" ]; then diff --git a/test/d-process_message-test.sh b/test/d-process_message-test.sh index 5b4c1e5..0c235ae 100755 --- a/test/d-process_message-test.sh +++ b/test/d-process_message-test.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -#### $$VERSION$$ v0.70-dev2-27-g2da31c1 +#### $$VERSION$$ v0.70-dev3-13-g81b540a # include common functions and definitions # shellcheck source=test/ALL-tests.inc.sh diff --git a/test/d-send_message-test.sh b/test/d-send_message-test.sh new file mode 100755 index 0000000..59063f7 --- /dev/null +++ b/test/d-send_message-test.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +#### $$VERSION$$ v0.70-dev3-13-g81b540a + +# include common functions and definitions +# shellcheck source=test/ALL-tests.inc.sh +source "./ALL-tests.inc.sh" + +set -e + +cd "${TESTDIR}" || exit 1 + +# source bashbot.sh function, uncomment if you want to test functions +# shellcheck source=./bashbot.sh +source "${TESTDIR}/bashbot.sh" source +source "${TESTDIR}/modules/background.sh" + +# start writing your tests here ... + +# over write sendJson to output parameter only +sendJson() { + printf 'chat:%s\tJSON:%s\nURL:%s\n\n' "${1}" "${2}" "${3}" +} + +# send text input to send_message + +#set -x +echo -n " Send line ..." +while IFS='' read -r line || [[ -n "$line" ]]; do + echo -n "." + send_message "123456" "$line" >>"${OUTPUTFILE}" +done < "${INPUTFILE}" 2>>"${LOGFILE}" +echo " done." + +diff -c "${REFFILE}" "${OUTPUTFILE}" || exit 1 +echo " ... all \"send_message\" functions seems to work as expected." +echo "${SUCCESS}" + + diff --git a/test/d-send_message-test/d-send_message-test.input b/test/d-send_message-test/d-send_message-test.input new file mode 100644 index 0000000..8fdcafb --- /dev/null +++ b/test/d-send_message-test/d-send_message-test.input @@ -0,0 +1,17 @@ +# test for text only output +This is a normal text +This is a normal text mynewlinestartshere with a line break +html_parse_mode This is a HTML text +html_parse_mode This is a HTML text mynewlinestartshere with a line break +markdown_parse_mode This is a *MARKDOWN* text +markdown_parse_mode This is a *MARKDOWN* text mynewlinestartshere with a line break + +# test for keyboard, file, venue output +Text plus keyboard will appear in chat mykeyboardstartshere [ "Yep, sure" , "No, highly unlikely" ] +Text plus file will appear in chat myfilelocationstartshere /home/user/doge.jpg +Text plus location will appear in chat mylatstartshere la10 mylongstartshere lo20 +Text plus vuene will appear in chat mylatstartshere la10 mylongstartshere lo20 mytitlestartshere my home myaddressstartshere Diagon Alley N. 37 +All in one will appear in chat mykeyboardstartshere [ "Yep, sure" , "No, highly unlikely" ] myfilelocationstartshere /home/user/doge.jpg mylatstartshere la10 mylongstartshere lo20 + +# test for new inline button +Text plus keyboard will appear in chat mybuttonstartshere "Button Text" "https://www..." diff --git a/test/d-send_message-test/d-send_message-test.result b/test/d-send_message-test/d-send_message-test.result new file mode 100644 index 0000000..7721a3c --- /dev/null +++ b/test/d-send_message-test/d-send_message-test.result @@ -0,0 +1,54 @@ +chat:123456 JSON:"text":"# test for text only output" +URL:https://api.telegram.org/botbashbottestscript/sendMessage + +chat:123456 JSON:"text":"This is a normal text" +URL:https://api.telegram.org/botbashbottestscript/sendMessage + +chat:123456 JSON:"text":"This is a normal text +with a line break" +URL:https://api.telegram.org/botbashbottestscript/sendMessage + +chat:123456 JSON:"text":" This is a HTML text","parse_mode":"html" +URL:https://api.telegram.org/botbashbottestscript/sendMessage + +chat:123456 JSON:"text":" This is a HTML text +with a line break","parse_mode":"html" +URL:https://api.telegram.org/botbashbottestscript/sendMessage + +chat:123456 JSON:"text":" This is a *MARKDOWN* text","parse_mode":"markdown" +URL:https://api.telegram.org/botbashbottestscript/sendMessage + +chat:123456 JSON:"text":" This is a *MARKDOWN* text +with a line break","parse_mode":"markdown" +URL:https://api.telegram.org/botbashbottestscript/sendMessage + +chat:123456 JSON:"text":"# test for keyboard, file, venue output" +URL:https://api.telegram.org/botbashbottestscript/sendMessage + +chat:123456 JSON:"text":"Text plus keyboard will appear in chat", "reply_markup": {"keyboard": [ [ "Yep, sure" , "No, highly unlikely" ] ] , "one_time_keyboard":true} +URL:https://api.telegram.org/botbashbottestscript/sendMessage + +chat:123456 JSON:"action": "upload_photo" +URL:https://api.telegram.org/botbashbottestscript/sendChatAction + +chat:123456 JSON:"latitude": la10, "longitude": lo20 +URL:https://api.telegram.org/botbashbottestscript/sendLocation + +chat:123456 JSON:"latitude": la10, "longitude": lo20, "address": "Diagon Alley N. 37", "title": "my home" +URL:https://api.telegram.org/botbashbottestscript/sendVenue + +chat:123456 JSON:"text":"All in one will appear in chat", "reply_markup": {"keyboard": [ [ "Yep, sure" , "No, highly unlikely" ] ] , "one_time_keyboard":true} +URL:https://api.telegram.org/botbashbottestscript/sendMessage + +chat:123456 JSON:"action": "upload_photo" +URL:https://api.telegram.org/botbashbottestscript/sendChatAction + +chat:123456 JSON:"latitude": la10, "longitude": lo20 +URL:https://api.telegram.org/botbashbottestscript/sendLocation + +chat:123456 JSON:"text":"# test for new inline button" +URL:https://api.telegram.org/botbashbottestscript/sendMessage + +chat:123456 JSON:"text":"Text plus keyboard will appear in chat mybuttonstartshere "Button Text" "https://www..."" +URL:https://api.telegram.org/botbashbottestscript/sendMessage +