2018-08-03 10:37:18 +03:00
|
|
|
#!/bin/bash
|
|
|
|
|
2019-02-17 16:04:17 +03:00
|
|
|
# 1) start server:
|
|
|
|
# without caching:
|
|
|
|
# REDIS_HOST=None CHEATSH_PORT=50000 python bin/srv.py
|
|
|
|
# (recommended)
|
|
|
|
# with caching:
|
|
|
|
# REDIS_PREFIX=TEST1 CHEATSH_PORT=50000 python bin/srv.py
|
|
|
|
# (for complex search queries + to test caching)
|
|
|
|
# 2) configure CHTSH_URL
|
|
|
|
# 3) run the script
|
|
|
|
|
2020-07-29 20:12:02 +03:00
|
|
|
# work from script's dir
|
|
|
|
cd "$(dirname "$0")" || exit
|
|
|
|
|
2020-07-29 22:44:18 +03:00
|
|
|
# detect Python - if not set in env, try default virtualenv
|
2019-05-11 13:35:32 +03:00
|
|
|
PYTHON="${PYTHON:-../ve/bin/python}"
|
2020-07-29 22:44:18 +03:00
|
|
|
# if no virtalenv, try current python3 binary
|
2020-07-30 02:24:54 +03:00
|
|
|
if ! command -v "$PYTHON" &> /dev/null; then
|
2020-07-29 22:44:18 +03:00
|
|
|
PYTHON=$(command -v python3)
|
|
|
|
fi
|
2020-07-29 22:59:09 +03:00
|
|
|
python_version="$($PYTHON -c 'import sys; print(sys.version_info[0])')"
|
|
|
|
echo "Using PYTHON $python_version: $PYTHON"
|
2019-05-11 13:35:32 +03:00
|
|
|
|
|
|
|
skip_online="${CHEATSH_TEST_SKIP_ONLINE:-NO}"
|
|
|
|
test_standalone="${CHEATSH_TEST_STANDALONE:-YES}"
|
|
|
|
show_details="${CHEATSH_TEST_SHOW_DETAILS:-YES}"
|
2020-07-30 23:03:44 +03:00
|
|
|
CHTSH_URL="${CHTSH_URL:-'http://localhost:8002'}"
|
2019-05-11 13:35:32 +03:00
|
|
|
|
2018-08-03 10:37:18 +03:00
|
|
|
TMP=$(mktemp /tmp/cht.sh.tests-XXXXXXXXXXXXXX)
|
|
|
|
TMP2=$(mktemp /tmp/cht.sh.tests-XXXXXXXXXXXXXX)
|
2019-02-16 22:53:18 +03:00
|
|
|
TMP3=$(mktemp /tmp/cht.sh.tests-XXXXXXXXXXXXXX)
|
|
|
|
trap 'rm -rf $TMP $TMP2 $TMP3' EXIT
|
2018-08-03 10:37:18 +03:00
|
|
|
|
2019-02-17 16:04:17 +03:00
|
|
|
CHTSH_SCRIPT=$(dirname "$(dirname "$(readlink -f "$0")")")/share/cht.sh.txt
|
2018-08-03 10:37:18 +03:00
|
|
|
|
2019-05-11 19:23:44 +03:00
|
|
|
export PYTHONIOENCODING=UTF-8
|
|
|
|
|
2018-08-03 10:37:18 +03:00
|
|
|
i=0
|
|
|
|
failed=0
|
2019-02-16 22:53:18 +03:00
|
|
|
{
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
cat -n tests.txt
|
|
|
|
else
|
2019-02-17 16:04:17 +03:00
|
|
|
cat -n tests.txt | sed -n "$(echo "$*" | sed 's/ /p; /g;s/$/p/')"
|
2019-02-16 22:53:18 +03:00
|
|
|
fi
|
|
|
|
} > "$TMP3"
|
2019-05-09 23:15:47 +03:00
|
|
|
|
|
|
|
|
2019-02-16 22:53:18 +03:00
|
|
|
while read -r number test_line; do
|
2020-07-30 22:20:58 +03:00
|
|
|
echo -e "\e[34mRunning $number: \e[36m$test_line\e[0m"
|
2019-05-09 23:15:47 +03:00
|
|
|
if [ "$skip_online" = YES ]; then
|
|
|
|
if [[ $test_line = *\[online\]* ]]; then
|
|
|
|
echo "$number is [online]; skipping"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2019-05-11 19:23:44 +03:00
|
|
|
if [[ "$python_version" = 2 ]] && [[ $test_line = *\[python3\]* ]]; then
|
2020-07-30 02:24:54 +03:00
|
|
|
echo "$number is for Python 3; skipping"
|
2019-05-11 19:23:44 +03:00
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "$python_version" = 3 ]] && [[ $test_line = *\[python2\]* ]]; then
|
2020-07-30 02:24:54 +03:00
|
|
|
echo "$number is for Python 2; skipping"
|
2019-05-11 19:23:44 +03:00
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2019-05-11 13:35:32 +03:00
|
|
|
#shellcheck disable=SC2001
|
|
|
|
test_line=$(echo "$test_line" | sed 's@ *#.*@@')
|
2019-05-09 23:15:47 +03:00
|
|
|
|
|
|
|
if [ "$test_standalone" = YES ]; then
|
2019-05-11 13:35:32 +03:00
|
|
|
test_line="${test_line//cht.sh /}"
|
2020-07-30 22:37:34 +03:00
|
|
|
[[ $show_details == YES ]] && echo "${PYTHON} ../lib/standalone.py $test_line"
|
|
|
|
"${PYTHON}" ../lib/standalone.py "$test_line" > "$TMP"
|
2019-05-09 23:15:47 +03:00
|
|
|
elif [[ $test_line = "cht.sh "* ]]; then
|
2019-02-16 22:53:18 +03:00
|
|
|
test_line="${test_line//cht.sh /}"
|
2020-07-30 22:37:34 +03:00
|
|
|
[[ $show_details == YES ]] && echo "bash $CHTSH_SCRIPT $test_line"
|
2019-02-16 22:53:18 +03:00
|
|
|
eval "bash $CHTSH_SCRIPT $test_line" > "$TMP"
|
|
|
|
else
|
2020-07-30 22:37:34 +03:00
|
|
|
[[ $show_details == YES ]] && echo "curl -s $CHTSH_URL/$test_line"
|
2019-02-16 22:53:18 +03:00
|
|
|
eval "curl -s $CHTSH_URL/$test_line" > "$TMP"
|
|
|
|
fi
|
2019-05-09 23:15:47 +03:00
|
|
|
|
2020-07-30 23:17:01 +03:00
|
|
|
if ! diff -u3 --color=always results/"$number" "$TMP" > "$TMP2"; then
|
2019-05-09 23:15:47 +03:00
|
|
|
if [ "$show_details" = YES ]; then
|
|
|
|
cat "$TMP2"
|
|
|
|
fi
|
2020-07-31 09:57:20 +03:00
|
|
|
if grep -q "Internal Server Error" "$TMP2"; then
|
|
|
|
[[ $TRAVIS == true ]] && docker-compose logs app
|
|
|
|
fi
|
2019-02-16 22:53:18 +03:00
|
|
|
echo "FAILED: [$number] $test_line"
|
2018-08-03 10:37:18 +03:00
|
|
|
((failed++))
|
|
|
|
fi
|
|
|
|
((i++))
|
2019-02-16 22:53:18 +03:00
|
|
|
done < "$TMP3"
|
2018-08-03 10:37:18 +03:00
|
|
|
|
2019-02-17 16:04:17 +03:00
|
|
|
echo TESTS/OK/FAILED "$i/$((i-failed))/$failed"
|
2018-08-03 10:37:18 +03:00
|
|
|
|
2019-05-11 14:08:49 +03:00
|
|
|
if [ "$failed" != 0 ]; then
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
exit 0
|
|
|
|
fi
|