Skip to content

Instantly share code, notes, and snippets.

@troelskn
Created July 3, 2009 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save troelskn/140064 to your computer and use it in GitHub Desktop.
Save troelskn/140064 to your computer and use it in GitHub Desktop.
#!/usr/bin/env sh
print_usage() {
printf "Usage: %s [-t=TESTFILE] [-w=WATCHDIR]\n" $(basename $0)
echo " TESTFILE Command to run test"
echo " WATCHDIR Dir to watch for changes"
exit 2
}
# you need these dependencies:
# sudo apt-get install inotify-tools
# sudo apt-get install libnotify-bin
check_dependencies() {
which notify-send > /dev/null
if [ $? -ne 0 ]
then
echo "notify-send not found" >&2
exit -1
fi
which inotifywait > /dev/null
if [ $? -ne 0 ]
then
echo "inotifywait not found" >&2
exit -1
fi
}
message() {
notify-send --icon=gtk-dialog-info "Test OK" "$1"
}
warn() {
notify-send --icon=gtk-dialog-warning "Test Failed" "$1"
}
error() {
notify-send --icon=gtk-dialog-error "Fatal error" "$1"
}
run_test() {
$TEST_COMMAND | while read line
do
echo $line
if echo $line | grep --quiet --perl-regexp --regexp='^[0-9]+ tests, [0-9]+ assertions, 0 failures, 0 errors$'
then
message "$line"
elif echo $line | grep --quiet --perl-regexp --regexp='^[0-9]+ tests, [0-9]+ assertions, [0-9]+ failures, [0-9]+ errors$'
then
warn "$line"
elif echo $line | grep --quiet --perl-regexp --regexp='^\(Fatal\|Parse\) error'
then
error "$line"
fi
done
}
watch() {
CHANGED_FILE=`inotifywait -rq --format '%f' -e modify $WATCH_DIRECTORY`
if [ -f $CHANGED_FILE ] && echo $CHANGED_FILE | grep --quiet --invert-match --perl-regexp --regexp='^#.*#$'
then
echo "$CHANGED_FILE changed"
run_test
fi
watch
}
#
# main
#
TEST_COMMAND="rake test"
WATCH_DIRECTORY="."
while getopts ht:w: OPTION
do
case $OPTION
in
t) TEST_COMMAND=${OPTARG}
;;
w) WATCH_DIRECTORY=${OPTARG}
;;
h) print_usage
;;
?) print_usage
;;
esac
done
check_dependencies
echo "Starting autotest"
echo " running tests with: $TEST_COMMAND"
echo " watching path: $WATCH_DIRECTORY"
run_test
watch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment