start test framework
This commit is contained in:
parent
41b8e6918d
commit
f53b8df40f
1
JSON.sh
1
JSON.sh
|
@ -1 +0,0 @@
|
|||
Subproject commit 022ec337c3225d5857856fd924cef0ab20443088
|
|
@ -102,4 +102,4 @@ Bashbot is not more (in)secure as any other Bot written in any other language, w
|
|||
|
||||
If you feel that there's something missing or if you found a bug, feel free to submit a pull request!
|
||||
|
||||
#### $$VERSION$$ v0.61-0-g3b17bc2
|
||||
#### $$VERSION$$ 0.70-dev-11-g41b8e69
|
||||
|
|
|
@ -166,5 +166,5 @@ That's it!
|
|||
If you feel that there's something missing or if you found a bug, feel
|
||||
free to submit a pull request!
|
||||
|
||||
latexmath:[\[VERSION\]] v0.61-0-g3b17bc2
|
||||
++++++++++++++++++++++++++++++++++++++++
|
||||
latexmath:[\[VERSION\]] 0.70-dev-11-g41b8e69
|
||||
++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/bin/sh
|
||||
# description: Start or stop telegram-bash-bot
|
||||
#
|
||||
#### $$VERSION$$ v0.61-0-g3b17bc2
|
||||
#### $$VERSION$$ 0.70-dev-11-g41b8e69
|
||||
# shellcheck disable=SC2009
|
||||
# shellcheck disable=SC2181
|
||||
|
||||
|
|
23
bashbot.sh
23
bashbot.sh
|
@ -10,7 +10,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.61-0-g3b17bc2
|
||||
#### $$VERSION$$ 0.70-dev-11-g41b8e69
|
||||
#
|
||||
# Exit Codes:
|
||||
# - 0 sucess (hopefully)
|
||||
|
@ -44,9 +44,9 @@ if [ ! -w "." ]; then
|
|||
ls -ld .
|
||||
fi
|
||||
|
||||
TOKEN="./token"
|
||||
if [ ! -f "${TOKEN}" ]; then
|
||||
if [ "${CLEAR}" = "" ]; then
|
||||
TOKENFILE="./token"
|
||||
if [ ! -f "${TOKENFILE}" ]; then
|
||||
if [ "${CLEAR}" = "" ] && [ "$1" != "init" ]; then
|
||||
echo "Running headless, run ${SCRIPT} init first!"
|
||||
exit 2
|
||||
else
|
||||
|
@ -54,13 +54,13 @@ if [ ! -f "${TOKEN}" ]; then
|
|||
echo -e "${RED}TOKEN MISSING.${NC}"
|
||||
echo -e "${ORANGE}PLEASE WRITE YOUR TOKEN HERE OR PRESS CTRL+C TO ABORT${NC}"
|
||||
read -r token
|
||||
echo "${token}" > "${TOKEN}"
|
||||
echo "${token}" > "${TOKENFILE}"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -f "JSON.sh/JSON.sh" ]; then
|
||||
echo "You did not clone recursively! Downloading JSON.sh..."
|
||||
git clone http://github.com/dominictarr/JSON.sh
|
||||
echo "Seems to be first run, Downloading JSON.sh..."
|
||||
git clone https://github.com/dominictarr/JSON.sh/ 2>&1
|
||||
echo "JSON.sh has been downloaded. Proceeding."
|
||||
fi
|
||||
|
||||
|
@ -603,8 +603,12 @@ getBotName() {
|
|||
|
||||
ME="$(getBotName)"
|
||||
if [ "$ME" = "" ]; then
|
||||
if [ "$(cat "${TOKENFILE}")" = "bashbottestscript" ]; then
|
||||
ME="bashbottestscript"
|
||||
else
|
||||
echo -e "${RED}ERROR: Can't connect to Telegram Bot! May be your TOKEN is invalid ...${NC}"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# use phyton JSON to decode JSON UFT-8, provide bash implementaion as fallback
|
||||
|
@ -687,14 +691,13 @@ case "$1" in
|
|||
echo -e "${RED}User \"$TOUSER\" not found!${NC}"
|
||||
exit 3
|
||||
else
|
||||
echo "Adjusting user in bashbot.rc ..."
|
||||
echo "Adjusting user \"${TOUSER}\" files and permissions ..."
|
||||
sed -i '/^[# ]*runas=/ s/runas=.*$/runas="'$TOUSER'"/' bashbot.rc
|
||||
echo "Adjusting Owner and Permissions ..."
|
||||
chown -R "$TOUSER" . ./*
|
||||
chmod 711 .
|
||||
chmod -R a-w ./*
|
||||
chmod -R u+w "${COUNT}" "${TMPDIR}" "${BOTADMIN}" ./*.log 2>/dev/null
|
||||
chmod -R o-r,o-w "${COUNT}" "${TMPDIR}" "${TOKEN}" "${BOTADMIN}" "${BOTACL}" 2>/dev/null
|
||||
chmod -R o-r,o-w "${COUNT}" "${TMPDIR}" "${TOKENFILE}" "${BOTADMIN}" "${BOTACL}" 2>/dev/null
|
||||
ls -la
|
||||
exit
|
||||
fi
|
||||
|
|
|
@ -4,7 +4,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.61-0-g3b17bc2
|
||||
#### $$VERSION$$ 0.70-dev-11-g41b8e69
|
||||
#
|
||||
# shellcheck disable=SC2154
|
||||
# shellcheck disable=SC2034
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.61-2-gfd4dd8c
|
||||
#### $$VERSION$$ 0.70-dev-11-g41b8e69
|
||||
|
||||
# magic to ensure that we're always inside the root of our application,
|
||||
# no matter from which directory we'll run script
|
||||
|
@ -28,8 +28,10 @@ else
|
|||
fi
|
||||
|
||||
# run shellcheck before commit
|
||||
echo "read files from dev/shellcheck.files ..."
|
||||
FILES=$(sed '/^#/d' <"dev/shellcheck.files")
|
||||
set +f
|
||||
FILES="$(find ./* -name '*.sh')"
|
||||
set -f
|
||||
FILES="${FILES} $(sed '/^#/d' <"dev/shellcheck.files")"
|
||||
if [ "$FILES" != "" ]; then
|
||||
# shellcheck disable=SC2086
|
||||
shellcheck -x ${FILES} || exit 1
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.61-2-gfd4dd8c
|
||||
#### $$VERSION$$ 0.70-dev-11-g41b8e69
|
||||
|
||||
# magic to ensure that we're always inside the root of our application,
|
||||
# no matter from which directory we'll run script
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env bash
|
||||
# this has to run once atfer git clone
|
||||
# and every time we create new hooks
|
||||
#### $$VERSION$$ v0.61-2-gfd4dd8c
|
||||
#### $$VERSION$$ 0.70-dev-11-g41b8e69
|
||||
|
||||
# magic to ensure that we're always inside the root of our application,
|
||||
# no matter from which directory we'll run script
|
||||
|
|
|
@ -1,15 +1,3 @@
|
|||
# list of files to run shellscheck against
|
||||
#### $$VERSION$$ v0.61-2-gfd4dd8c
|
||||
# main files
|
||||
bashbot.sh
|
||||
commands.sh
|
||||
# list of additional files to check from shellcheck
|
||||
#### $$VERSION$$ 0.70-dev-11-g41b8e69
|
||||
bashbot.rc
|
||||
# example files
|
||||
examples/calc.sh
|
||||
examples/notify.sh
|
||||
examples/question.sh
|
||||
# dev files
|
||||
dev/version.sh
|
||||
dev/install-hooks.sh
|
||||
dev/hooks/pre-commit.sh
|
||||
dev/hooks/pre-push.sh
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
#### $$VERSION$$ v0.61-2-gfd4dd8c
|
||||
#### $$VERSION$$ 0.70-dev-11-g41b8e69
|
||||
# shellcheck disable=SC2016
|
||||
#
|
||||
# Easy Versioning in git:
|
||||
|
@ -45,7 +45,7 @@ unset IFS
|
|||
VERSION="$(git describe --tags --long)"
|
||||
echo "Update to version $VERSION ..."
|
||||
|
||||
FILES="* doc/* dev/* dev/*/*"
|
||||
FILES="$(find ./*)"
|
||||
[ "$1" != "" ] && FILES="$*"
|
||||
|
||||
for file in $FILES
|
||||
|
|
|
@ -61,5 +61,5 @@ group. This step is up to you actually.
|
|||
|
||||
#### [Next Getting started](2_usage.md)
|
||||
|
||||
#### $$VERSION$$ v0.61-2-gfd4dd8c
|
||||
#### $$VERSION$$ 0.70-dev-11-g41b8e69
|
||||
|
||||
|
|
|
@ -159,5 +159,5 @@ send_action "${CHAT[ID]}" "action"
|
|||
#### [Prev Create Bot](1_firstbot.md)
|
||||
#### [Next Advanced Usage](3_advanced.md)
|
||||
|
||||
#### $$VERSION$$ v0.61-2-gfd4dd8c
|
||||
#### $$VERSION$$ 0.70-dev-11-g41b8e69
|
||||
|
||||
|
|
|
@ -156,5 +156,5 @@ answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker"
|
|||
#### [Prev Advanced Usage](3_advanced.md)
|
||||
#### [Next Expert Use](4_expert.md)
|
||||
|
||||
#### $$VERSION$$ v0.61-2-gfd4dd8c
|
||||
#### $$VERSION$$ 0.70-dev-11-g41b8e69
|
||||
|
||||
|
|
|
@ -104,5 +104,5 @@ An example crontab is provided in ```examples/bashbot.cron```.
|
|||
#### [Prev Expert Use](4_expert.md)
|
||||
#### [Next Best Practice](5_practice.md)
|
||||
|
||||
#### $$VERSION$$ v0.61-2-gfd4dd8c
|
||||
#### $$VERSION$$ 0.70-dev-11-g41b8e69
|
||||
|
||||
|
|
|
@ -112,5 +112,5 @@ The second warning is about an unused variable, this is true because in our exam
|
|||
#### [Prev Best Practice](5_practice.md)
|
||||
#### [Next Functions Reference](6_reference.md)
|
||||
|
||||
#### $$VERSION$$ v0.61-2-gfd4dd8c
|
||||
#### $$VERSION$$ 0.70-dev-11-g41b8e69
|
||||
|
||||
|
|
|
@ -348,5 +348,5 @@ Send Input from Telegram to waiting Interactive Chat.
|
|||
#### [Prev Best Practice](5_practice.md)
|
||||
#### [Next Developer Rules](7_develop.md)
|
||||
|
||||
#### $$VERSION$$ v0.61-2-gfd4dd8c
|
||||
#### $$VERSION$$ 0.70-dev-11-g41b8e69
|
||||
|
||||
|
|
|
@ -31,7 +31,37 @@ For a shell script running as a service it's important to be paranoid about quot
|
|||
In addition you can run ```dev/hooks/pre-commit.sh``` every time you want to shellcheck all files given in 'dev/shellcheck.files'.
|
||||
|
||||
|
||||
## bashbot tests
|
||||
Starting with version 0.70 bashbot has a test suite. To start testsuite run ```test/ALL-tests.sh```. ALL-tests.sh will only return 'SUCCESS' if all tests pass.
|
||||
|
||||
### creating new tests
|
||||
To create a new test create a new bash script named ```p-name-test.sh```, where p is pass 'a-z' and name the name of your test.
|
||||
All tests with the same pass are performed together.
|
||||
|
||||
Tests with no dependency to other tests will run in pass 'a', tests which need an initialized bahsbot environment must run in pass 'c' or later.
|
||||
If '$1' is present the script is started from 'ALL-tests.sh' and the script runs in a temporary test environment in directory '$1'.
|
||||
The temporary test environment is created when 'ALL-tests.sh' starts and deleted after all tests are finished.
|
||||
|
||||
Example test
|
||||
```bash
|
||||
|
||||
#!/usr/bin/env bash
|
||||
# file: z-bashbot-test.sh
|
||||
|
||||
# this test should always pass :-)
|
||||
echo "Running test if bashbot.sh exists"
|
||||
echo "................................."
|
||||
|
||||
if [ -f "bashbot.sh" ]; then
|
||||
echo "bashbot.sh OK!"
|
||||
exit 0
|
||||
else
|
||||
echo "bashbot.sh missing!"
|
||||
exit 1
|
||||
fi
|
||||
```
|
||||
|
||||
#### [Prev Function Reference](6_function.md)
|
||||
|
||||
#### $$VERSION$$ v0.61-2-gfd4dd8c
|
||||
#### $$VERSION$$ 0.70-dev-11-g41b8e69
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ 0.70-dev-4-g12fd839
|
||||
#### $$VERSION$$ 0.70-dev-11-g41b8e69
|
||||
|
||||
|
||||
SHELL=/bin/sh
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
|
||||
#### $$VERSION$$ 0.70-dev-4-g12fd839
|
||||
#### $$VERSION$$ 0.70-dev-11-g41b8e69
|
||||
|
||||
# adjust your language setting here
|
||||
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#### $$VERSION$$ 0.70-dev-4-g12fd839
|
||||
#### $$VERSION$$ 0.70-dev-11-g41b8e69
|
||||
|
||||
# adjust your language setting here
|
||||
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
|
||||
#### $$VERSION$$ 0.70-dev-4-g12fd839
|
||||
#### $$VERSION$$ 0.70-dev-11-g41b8e69
|
||||
|
||||
# adjust your language setting here
|
||||
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
#!/bin/bash
|
||||
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
|
||||
#### $$VERSION$$ 0.70-dev-11-g41b8e69
|
||||
|
||||
# adjust your language setting here
|
||||
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
||||
export 'LC_ALL=C.UTF-8'
|
||||
export 'LANG=C.UTF-8'
|
||||
export 'LANGUAGE=C.UTF-8'
|
||||
|
||||
unset IFS
|
||||
# set -f # if you are paranoid use set -f to disable globbing
|
||||
|
||||
echo "Why hello there.
|
||||
Would you like some tea (y/n)?"
|
||||
read -r answer
|
||||
[[ $answer =~ ^([yY][eE][sS]|[yY])$ ]] && echo "OK then, here you go: http://www.rivertea.com/blog/wp-content/uploads/2013/12/Green-Tea.jpg" || echo "OK then."
|
||||
until [ "$SUCCESS" = "y" ] ;do
|
||||
echo 'Do you like Music? mykeyboardstartshere "Yass!" , "No"'
|
||||
read -r answer
|
||||
case $answer in
|
||||
'Yass!') echo "Goody! mykeyboardendshere";SUCCESS=y;;
|
||||
'No') echo "Well that's weird. mykeyboardendshere";SUCCESS=y;;
|
||||
*) SUCCESS=n;;
|
||||
esac
|
||||
done
|
||||
exit
|
|
@ -0,0 +1,49 @@
|
|||
#!/usr/bin/env bash
|
||||
# this has to run once atfer git clone
|
||||
# and every time we create new hooks
|
||||
#### $$VERSION$$ 0.70-dev-11-g41b8e69
|
||||
|
||||
# magic to ensure that we're always inside the root of our application,
|
||||
# no matter from which directory we'll run script
|
||||
GIT_DIR=$(git rev-parse --git-dir)
|
||||
cd "${GIT_DIR}/.." || exit 1
|
||||
|
||||
# create test environment
|
||||
TESTENV="/tmp/bashbot.test$$"
|
||||
cp -r . "${TESTENV}"
|
||||
|
||||
#set -e
|
||||
fail=0
|
||||
tests=0
|
||||
passed=0
|
||||
#all_tests=${__dirname:}
|
||||
#echo PLAN ${#all_tests}
|
||||
for test in $(find test/*-test.sh | sort -u) ;
|
||||
do
|
||||
[ "${test}" = "test/all-tests.sh" ] && continue
|
||||
[ ! -x "${test}" ] && continue
|
||||
tests=$((tests+1))
|
||||
echo "TEST: ${test}"
|
||||
"${test}" "${TESTENV}"
|
||||
ret=$?
|
||||
if [ "$ret" -eq 0 ] ; then
|
||||
echo "OK: ---- ${test}"
|
||||
passed=$((passed+1))
|
||||
else
|
||||
echo "FAIL: $test $fail"
|
||||
fail=$((fail+ret))
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$fail" -eq 0 ]; then
|
||||
/bin/echo -n 'SUCCESS '
|
||||
exitcode=0
|
||||
else
|
||||
/bin/echo -n 'FAILURE '
|
||||
exitcode=1
|
||||
fi
|
||||
|
||||
rm -rf "${TESTENV}"
|
||||
echo "${passed} / ${tests}"
|
||||
exit ${exitcode}
|
|
@ -0,0 +1,10 @@
|
|||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ 0.70-dev-11-g41b8e69
|
||||
|
||||
# magic to ensure that we're always inside the root of our application,
|
||||
# no matter from which directory we'll run script
|
||||
GIT_DIR=$(git rev-parse --git-dir)
|
||||
cd "$GIT_DIR/.." || exit 1
|
||||
|
||||
dev/hooks/pre-commit.sh
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ 0.70-dev-11-g41b8e69
|
||||
|
||||
# magic to ensure that we're always inside the root of our application,
|
||||
# no matter from which directory we'll run script
|
||||
GIT_DIR=$(git rev-parse --git-dir)
|
||||
cd "$GIT_DIR/.." || exit 1
|
||||
|
||||
dev/hooks/pre-push.sh
|
|
@ -0,0 +1,28 @@
|
|||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ 0.70-dev-11-g41b8e69
|
||||
|
||||
# magic to ensure that we're always inside the root of our application,
|
||||
# no matter from which directory we'll run script
|
||||
GIT_DIR=$(git rev-parse --git-dir)
|
||||
cd "$GIT_DIR/.." || exit 1
|
||||
|
||||
TESTME="$(basename "$0")"
|
||||
set -e
|
||||
|
||||
# let's fake failing test for now
|
||||
echo "Running bashbot init"
|
||||
echo "............................"
|
||||
# change to test env
|
||||
[ "$1" = "" ] && echo "not called from testsuite, exit" && exit
|
||||
cd "$1" || exit 1
|
||||
|
||||
|
||||
unset IFS; set -f
|
||||
|
||||
# run bashbot first time with init
|
||||
export TERM=""
|
||||
"${1}/bashbot.sh" init >"${TESTME}.log" <<EOF
|
||||
bashbottestscript
|
||||
nobody
|
||||
botadmin
|
||||
EOF
|
Loading…
Reference in New Issue