diff --git a/.test/run b/.test/run index 4cba339..5c5690f 100755 --- a/.test/run +++ b/.test/run @@ -12,18 +12,27 @@ do done echo "--- Running test.py ---" -if ! python test.py >/dev/null +if ! .test/timeout -t 60 python test.py >/dev/null then echo "Running test.py failed" exit -2 fi +FAIL="" echo "--- Running Tests ---" for i in $(ls .test/test*.py) do - if ! python $i + if ! .test/timeout -t 60 python $i then - echo "Test '$i' failed" - exit -3 + FAIL="$FAIL $i" + echo "-> Failed" + else + echo "-> Passed" fi done + +if ! test -z "$FAIL" +then + echo "Some tests failed." + exit -3 +fi diff --git a/.test/timeout b/.test/timeout new file mode 100755 index 0000000..5c19d2e --- /dev/null +++ b/.test/timeout @@ -0,0 +1,91 @@ +#!/bin/bash +# +# The Bash shell script executes a command with a time-out. +# Upon time-out expiration SIGTERM (15) is sent to the process. If the signal +# is blocked, then the subsequent SIGKILL (9) terminates it. +# +# Based on the Bash documentation example. + +# Hello Chet, +# please find attached a "little easier" :-) to comprehend +# time-out example. If you find it suitable, feel free to include +# anywhere: the very same logic as in the original examples/scripts, a +# little more transparent implementation to my taste. +# +# Dmitry V Golovashkin + +scriptName="${0##*/}" + +declare -i DEFAULT_TIMEOUT=9 +declare -i DEFAULT_INTERVAL=1 +declare -i DEFAULT_DELAY=1 + +# Timeout. +declare -i timeout=DEFAULT_TIMEOUT +# Interval between checks if the process is still alive. +declare -i interval=DEFAULT_INTERVAL +# Delay between posting the SIGTERM signal and destroying the process by SIGKILL. +declare -i delay=DEFAULT_DELAY + +function printUsage() { + cat < 0)); do + sleep $interval + kill -0 $$ || exit 0 + ((t -= interval)) + done + + # Be nice, post SIGTERM first. + # The 'exit 0' below will be executed if any preceeding command fails. + kill -s SIGTERM $$ && kill -0 $$ || exit 0 + sleep $delay + kill -s SIGKILL $$ +) 2> /dev/null & + +exec "$@" diff --git a/README.md b/README.md index 2b11e90..2707c78 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,8 @@ You should test your functions before you submit them to us. Especially in this After you've solved all the excercises, push them all to your fork. Check if all your changes are visible on github.com and create a Pull Request (a nice green button on top of your fork page). The pull request will be automagickly tested with [Travis-CI](https://travis-ci.org/). The results will show as a green checkmark or a sad red x. +**IMPORTANT:** *In this task, you cannot use `scipy`, `numpy`, or `matplotlib`* + ### Open source and public work Yes, we know that you can open another person's fork and copy the solutions. Yay, you got an green checkmark for free! You can be proud of yourself. Have [another one](https://solidwize.com/wp-content/uploads/2012/04/Green-Check-Mark.jpg). Freshly copy-pasted from [google images](http://images.lmgtfy.com/?q=checkmark).