-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run tests on Travis CI #224
Changes from all commits
ce7b4c8
40d18da
06d8fa7
3905047
c515c56
1a1624e
1a5aa64
60ae85e
09dff20
c0bbc24
4610690
1387f8b
5737a16
a0d344c
e0f84e8
1032623
be9d3a7
6be6a25
9a495a7
5dab632
10bfaab
2e1d804
f62fb51
ca55415
198a2c4
acd07d2
ee273e2
91320d9
36a7cd3
ca88810
b74707a
18e851c
7578ab7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Compose override to add --debug option to bin/srv.py | ||
# call to print tracebacks on errors to stdout. | ||
# | ||
# See https://docs.docker.com/compose/extends/ | ||
version: '2' | ||
services: | ||
app: | ||
command: "--debug" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,28 +2,37 @@ | |
|
||
# 1) start server: | ||
# without caching: | ||
# REDIS_HOST=None CHEATSH_PORT=50000 python bin/srv.py | ||
# CHEATSH_CACHE_TYPE=none CHEATSH_PORT=50000 python bin/srv.py | ||
# (recommended) | ||
# with caching: | ||
# REDIS_PREFIX=TEST1 CHEATSH_PORT=50000 python bin/srv.py | ||
# CHEATSH_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 | ||
|
||
# work from script's dir | ||
cd "$(dirname "$0")" || exit | ||
abitrolly marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# detect Python - if not set in env, try default virtualenv | ||
PYTHON="${PYTHON:-../ve/bin/python}" | ||
"$PYTHON" --version 2>&1 | grep -q 'Python 2' && python_version=2 || python_version=3 | ||
# if no virtalenv, try current python3 binary | ||
if ! command -v "$PYTHON" &> /dev/null; then | ||
PYTHON=$(command -v python3) | ||
abitrolly marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fi | ||
python_version="$($PYTHON -c 'import sys; print(sys.version_info[0])')" | ||
echo "Using PYTHON $python_version: $PYTHON" | ||
|
||
skip_online="${CHEATSH_TEST_SKIP_ONLINE:-NO}" | ||
test_standalone="${CHEATSH_TEST_STANDALONE:-YES}" | ||
show_details="${CHEATSH_TEST_SHOW_DETAILS:-YES}" | ||
update_tests_results="${CHEATSH_UPDATE_TESTS_RESULTS:-NO}" | ||
CHTSH_URL="${CHTSH_URL:-http://localhost:8002}" | ||
|
||
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 | ||
|
||
export CHTSH_URL=http://cht.sh:50000 | ||
CHTSH_SCRIPT=$(dirname "$(dirname "$(readlink -f "$0")")")/share/cht.sh.txt | ||
|
||
export PYTHONIOENCODING=UTF-8 | ||
|
@@ -40,6 +49,7 @@ failed=0 | |
|
||
|
||
while read -r number test_line; do | ||
echo -e "\e[34mRunning $number: \e[36m$test_line\e[0m" | ||
if [ "$skip_online" = YES ]; then | ||
if [[ $test_line = *\[online\]* ]]; then | ||
echo "$number is [online]; skipping" | ||
|
@@ -48,10 +58,12 @@ while read -r number test_line; do | |
fi | ||
|
||
if [[ "$python_version" = 2 ]] && [[ $test_line = *\[python3\]* ]]; then | ||
echo "$number is for Python 3; skipping" | ||
continue | ||
fi | ||
|
||
if [[ "$python_version" = 3 ]] && [[ $test_line = *\[python2\]* ]]; then | ||
echo "$number is for Python 2; skipping" | ||
continue | ||
fi | ||
|
||
|
@@ -60,20 +72,25 @@ while read -r number test_line; do | |
|
||
if [ "$test_standalone" = YES ]; then | ||
test_line="${test_line//cht.sh /}" | ||
"${PYTHON}" ../lib/standalone.py "$test_line" > "$TMP" 2> /dev/null | ||
[[ $show_details == YES ]] && echo "${PYTHON} ../lib/standalone.py $test_line" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could convert this to a function which takes the string as an argument. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure I am that bash proficient. Show an example? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
"${PYTHON}" ../lib/standalone.py "$test_line" > "$TMP" | ||
elif [[ $test_line = "cht.sh "* ]]; then | ||
test_line="${test_line//cht.sh /}" | ||
[[ $show_details == YES ]] && echo "bash $CHTSH_SCRIPT $test_line" | ||
eval "bash $CHTSH_SCRIPT $test_line" > "$TMP" | ||
else | ||
[[ $show_details == YES ]] && echo "curl -s $CHTSH_URL/$test_line" | ||
eval "curl -s $CHTSH_URL/$test_line" > "$TMP" | ||
fi | ||
|
||
if ! diff results/"$number" "$TMP" > "$TMP2"; then | ||
if ! diff -u3 --color=always results/"$number" "$TMP" > "$TMP2"; then | ||
if [[ $CHEATSH_UPDATE_TESTS_RESULTS = NO ]]; then | ||
if [ "$show_details" = YES ]; then | ||
echo "$ CHEATSH_CACHE_TYPE=none python ../lib/standalone.py $test_line" | ||
cat "$TMP2" | ||
fi | ||
if grep -q "Internal Server Error" "$TMP2"; then | ||
[[ $TRAVIS == true ]] && docker logs chtsh | ||
fi | ||
echo "FAILED: [$number] $test_line" | ||
else | ||
cat "$TMP" > results/"$number" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sleep is probably not a good way to know when the server is up. If you run it locally on a slower machine this can easily fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, cap. So any ideas how to fix that - https://travis-ci.com/github/abitrolly/cheat.sh/builds/177678164#L390? I checked - it is non-trivial
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Retry after one second up to X if the exit code is 52 maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How exit code 52 is related?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then maybe better check until a port is accepting connections?