telegram-bot-bash/test/ADD-test-new.sh

102 lines
2.9 KiB
Bash
Raw Normal View History

2019-04-23 12:53:14 +00:00
#!/usr/bin/env bash
2021-01-02 16:21:28 +00:00
#===============================================================================
2019-04-23 12:53:14 +00:00
#
2021-01-02 16:21:28 +00:00
# FILE: ADD-test-new.sh
#
# USAGE: ADD-test-new.sh
2019-04-23 12:53:14 +00:00
#
2021-01-02 16:21:28 +00:00
# DESCRIPTION: creates interactive a new test skeleton, but does not activate test
#
# LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
#
#### $$VERSION$$ v1.25-dev-14-g2fe6d4b
2021-01-02 16:21:28 +00:00
#===============================================================================
2019-04-23 12:53:14 +00:00
# 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
2021-01-02 16:21:28 +00:00
printf "\nDo your really want to create an new test for bashbot test suite? (y/N) N\b"
2019-04-23 12:53:14 +00:00
read -r REALLY
2021-01-02 16:21:28 +00:00
[ "${REALLY}" != "y" ] && printf "Stop ...\n\n" && exit 1
2019-04-23 12:53:14 +00:00
# enter name
2021-01-02 16:21:28 +00:00
printf "\nEnter Name for the the new test, 6+ chars, no :space: (empty to stop) stop\b\b\b\b"
2019-04-23 12:53:14 +00:00
read -r NAME
2021-01-02 16:21:28 +00:00
if [ "${NAME}" = "" ] || [ "${NAME}" = "" ]; then printf "Stop ...\n\n"; exit 1; fi
2019-04-23 12:53:14 +00:00
# enter pass a-z
2021-01-02 16:21:28 +00:00
printf "\nEnter PASS \"a\" to \"z\" to execute the new test, d\b"
2019-04-23 12:53:14 +00:00
read -r PASS
# pass to lower, default pass d
PASS="${PASS,,}"
[ "${PASS}" = "" ] && PASS="d"
2021-01-02 16:21:28 +00:00
[ "${#PASS}" != '1' ] && printf "SORRY: PASS must exactly one character from a to z! Stop ...\n\n" && exit 1
2019-04-23 12:53:14 +00:00
TEST="${PASS}-${NAME}-test"
2021-01-02 16:21:28 +00:00
printf "%s\n\n" " OK! Let's create test name \"${NAME}\" for pass \"${PASS}\"."
2019-04-23 12:53:14 +00:00
# check if already exist
if [ -f "test/${TEST}.sh" ] || [ -d "test/${TEST}" ]; then
2021-01-02 16:21:28 +00:00
printf "%s\n\n" "SORRY: Test test/${TEST}.sh already exists! Stop ..."
2019-04-23 12:53:14 +00:00
exit 1
fi
2021-01-02 16:21:28 +00:00
printf "The following files will be created:\n"
printf "%s\n%s\n%s\n" " test/${TEST}.sh" " test/${TEST}/${TEST}.input" " test/${TEST}/${TEST}.result"
2019-04-23 12:53:14 +00:00
2021-01-02 16:21:28 +00:00
printf "\nCreate the new test for bashbot test suite? (y/N) N\b"
2019-04-23 12:53:14 +00:00
read -r REALLY
2021-01-02 16:21:28 +00:00
[ "${REALLY}" != "y" ] && printf "Stop ...\n\n" && exit 1
2019-04-23 12:53:14 +00:00
2021-01-02 16:21:28 +00:00
printf " OK!\n\n"
2019-04-23 12:53:14 +00:00
# create files
cat >"test/${TEST}.sh" <<EOF
#!/usr/bin/env bash
2021-01-02 16:21:28 +00:00
#===============================================================================
#
# FILE: test/${TEST}.sh
#
# USAGE: must run only from dev/all-tests.sh
#
# DESCRIPTION: test ,,,
#
# LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/
# AUTHOR: yourname, your@e-mail.com
#
2019-04-23 12:53:14 +00:00
#### \$\$VERSION\$\$
2021-01-02 16:21:28 +00:00
#===============================================================================
2019-04-23 12:53:14 +00:00
# include common functions and definitions
# shellcheck source=test/ALL-tests.inc.sh
source "./ALL-tests.inc.sh"
set -e
2019-04-23 13:48:58 +00:00
cd "\${TESTDIR}" || exit 1
# source bashbot.sh function, uncomment if you want to test functions
# shellcheck source=./bashbot.sh
2021-01-02 16:21:28 +00:00
# source "\${TESTDIR}/bashbot.sh" source
# source "\${TESTDIR}/commands.sh" source
2019-04-23 13:48:58 +00:00
2019-04-23 12:53:14 +00:00
# start writing your tests here ...
EOF
mkdir "test/${TEST}"
touch "test/${TEST}/${TEST}.input" "test/${TEST}/${TEST}.result"
set +f
ls -l test/"${PASS}"-"${NAME}"-*
2021-01-02 16:21:28 +00:00
printf "\nDone.\n"