1
1
mirror of https://github.com/chubin/cheat.sh.git synced 2024-11-29 23:36:40 +03:00
cheat.sh/tests/run-tests.sh

88 lines
2.2 KiB
Bash
Raw Normal View History

2018-08-03 10:37:18 +03:00
#!/bin/bash
# 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
PYTHON="${PYTHON:-../ve/bin/python}"
"$PYTHON" --version 2>&1 | grep -q 'Python 2' && python_version=2 || python_version=3
skip_online="${CHEATSH_TEST_SKIP_ONLINE:-NO}"
test_standalone="${CHEATSH_TEST_STANDALONE:-YES}"
show_details="${CHEATSH_TEST_SHOW_DETAILS:-YES}"
2018-08-03 10:37:18 +03:00
TMP=$(mktemp /tmp/cht.sh.tests-XXXXXXXXXXXXXX)
TMP2=$(mktemp /tmp/cht.sh.tests-XXXXXXXXXXXXXX)
TMP3=$(mktemp /tmp/cht.sh.tests-XXXXXXXXXXXXXX)
trap 'rm -rf $TMP $TMP2 $TMP3' EXIT
2018-08-03 10:37:18 +03:00
export CHTSH_URL=http://cht.sh:50000
CHTSH_SCRIPT=$(dirname "$(dirname "$(readlink -f "$0")")")/share/cht.sh.txt
2018-08-03 10:37:18 +03:00
export PYTHONIOENCODING=UTF-8
2018-08-03 10:37:18 +03:00
i=0
failed=0
{
if [ -z "$1" ]; then
cat -n tests.txt
else
cat -n tests.txt | sed -n "$(echo "$*" | sed 's/ /p; /g;s/$/p/')"
fi
} > "$TMP3"
2019-05-09 23:15:47 +03:00
while read -r number test_line; do
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
if [[ "$python_version" = 2 ]] && [[ $test_line = *\[python3\]* ]]; then
continue
fi
if [[ "$python_version" = 3 ]] && [[ $test_line = *\[python2\]* ]]; then
continue
fi
#shellcheck disable=SC2001
test_line=$(echo "$test_line" | sed 's@ *#.*@@')
2019-05-09 23:15:47 +03:00
if [ "$test_standalone" = YES ]; then
test_line="${test_line//cht.sh /}"
"${PYTHON}" ../lib/standalone.py "$test_line" > "$TMP" 2> /dev/null
2019-05-09 23:15:47 +03:00
elif [[ $test_line = "cht.sh "* ]]; then
test_line="${test_line//cht.sh /}"
eval "bash $CHTSH_SCRIPT $test_line" > "$TMP"
else
eval "curl -s $CHTSH_URL/$test_line" > "$TMP"
fi
2019-05-09 23:15:47 +03:00
if ! diff results/"$number" "$TMP" > "$TMP2"; then
2019-05-09 23:15:47 +03:00
if [ "$show_details" = YES ]; then
echo "$ CHEATSH_CACHE_TYPE=none python ../lib/standalone.py $test_line"
cat "$TMP2"
fi
echo "FAILED: [$number] $test_line"
2018-08-03 10:37:18 +03:00
((failed++))
fi
((i++))
done < "$TMP3"
2018-08-03 10:37:18 +03:00
echo TESTS/OK/FAILED "$i/$((i-failed))/$failed"
2018-08-03 10:37:18 +03:00
if [ "$failed" != 0 ]; then
exit 1
else
exit 0
fi