2012-10-09 11:45:20 -04:00
|
|
|
#!/bin/bash
|
2012-10-04 07:24:03 -04:00
|
|
|
|
2012-10-10 20:43:13 -04:00
|
|
|
indent() {
|
|
|
|
level="$1"
|
|
|
|
printf "%$((2 * ${level}))s"
|
|
|
|
}
|
|
|
|
|
2012-10-04 07:29:34 -04:00
|
|
|
recurse() {
|
|
|
|
potential_test="$1"
|
2012-10-10 20:43:13 -04:00
|
|
|
indent_level="$2"
|
2012-10-10 14:40:49 -04:00
|
|
|
|
2012-10-10 14:43:41 -04:00
|
|
|
[ "$potential_test" = 'setup_dir' ] && return
|
|
|
|
[ "$potential_test" = 'teardown_dir' ] && return
|
|
|
|
[ "$potential_test" = 'setup' ] && return
|
|
|
|
[ "$potential_test" = 'teardown' ] && return
|
2012-10-10 14:40:49 -04:00
|
|
|
|
2012-10-11 01:15:48 -04:00
|
|
|
echo > "$stdout_file"
|
2012-10-10 20:31:18 -04:00
|
|
|
|
2012-10-04 07:29:34 -04:00
|
|
|
if [ -d "$potential_test" ]
|
|
|
|
then
|
|
|
|
(
|
2012-10-10 20:43:13 -04:00
|
|
|
indent $indent_level
|
|
|
|
echo " ${potential_test}"
|
2012-10-04 07:29:34 -04:00
|
|
|
cd "$potential_test"
|
2012-10-11 14:00:55 -04:00
|
|
|
[ -f setup_dir ] && [ -x setup_dir ] && ./setup_dir >> $stdout_file
|
2012-10-08 10:16:49 -04:00
|
|
|
for test in *
|
2012-10-10 20:31:18 -04:00
|
|
|
do
|
2012-10-11 14:00:55 -04:00
|
|
|
[ -f setup ] && [ -x setup ] && ./setup >> $stdout_file
|
2012-10-10 20:43:13 -04:00
|
|
|
|
|
|
|
# $2 instead of $indent_level so it doesn't clash
|
|
|
|
recurse "${test}" $(( $2 + 1 ))
|
|
|
|
|
2012-10-11 14:00:55 -04:00
|
|
|
[ -f teardown ] && [ -x teardown ] && ./teardown >> $stdout_file
|
2012-10-08 08:50:48 -04:00
|
|
|
done
|
2012-10-11 14:00:55 -04:00
|
|
|
[ -f teardown_dir ] && [ -x teardown_dir ] && ./teardown_dir >> $stdout_file
|
2012-10-11 01:17:20 -04:00
|
|
|
echo
|
2012-10-04 07:29:34 -04:00
|
|
|
)
|
2012-10-08 08:59:14 -04:00
|
|
|
elif [ -x "$potential_test" ]
|
2012-10-04 07:29:34 -04:00
|
|
|
then
|
2012-10-10 14:25:44 -04:00
|
|
|
|
2012-10-11 14:00:55 -04:00
|
|
|
[ -f setup ] && [ -x setup ] && ./setup >> $stdout_file
|
2012-10-10 15:47:21 -04:00
|
|
|
|
2012-10-10 14:25:44 -04:00
|
|
|
# Run the test
|
2012-10-11 14:00:55 -04:00
|
|
|
./"$potential_test" &> $stdout_file
|
2012-10-10 14:40:49 -04:00
|
|
|
exit_code="$?"
|
2012-10-10 15:47:21 -04:00
|
|
|
|
2012-10-11 14:00:55 -04:00
|
|
|
[ -f teardown ] && [ -x teardown ] && ./teardown >> $stdout_file
|
2012-10-10 14:25:44 -04:00
|
|
|
|
2012-10-10 20:43:13 -04:00
|
|
|
indent $indent_level
|
2012-10-10 14:40:49 -04:00
|
|
|
if [ "$exit_code" = '0' ]
|
2012-10-04 07:29:34 -04:00
|
|
|
then
|
2012-10-10 14:25:44 -04:00
|
|
|
# On success, print a '✓'
|
2012-10-09 11:45:20 -04:00
|
|
|
echo -ne '\033[32m✓ \033[0m'
|
|
|
|
echo "${potential_test}"
|
2012-10-11 01:10:43 -04:00
|
|
|
echo "${potential_test} passed" >> "$logfile"
|
2012-10-04 07:29:34 -04:00
|
|
|
else
|
2012-10-10 14:25:44 -04:00
|
|
|
# On fail, print a red '✗'
|
2012-10-09 11:45:20 -04:00
|
|
|
echo -ne '\033[31m✗ \033[0m'
|
|
|
|
echo "${potential_test}"
|
2012-10-11 01:10:43 -04:00
|
|
|
echo "${potential_test} failed" >> "$logfile"
|
2012-10-10 19:46:58 -04:00
|
|
|
cat $stdout_file
|
2012-10-04 07:29:34 -04:00
|
|
|
fi
|
2012-10-09 11:45:20 -04:00
|
|
|
rm $stdout_file
|
2012-10-04 07:29:34 -04:00
|
|
|
fi
|
|
|
|
}
|
2012-10-04 12:43:49 -04:00
|
|
|
|
2012-10-11 01:46:02 -04:00
|
|
|
USAGE="usage: $0 <test directory>"
|
|
|
|
|
2012-10-11 02:21:05 -04:00
|
|
|
urchin_help() {
|
2012-10-11 01:52:29 -04:00
|
|
|
echo
|
|
|
|
echo "$USAGE"
|
|
|
|
echo
|
|
|
|
echo '-f Force urchin to run on directories not named "test".'
|
|
|
|
echo '-h This help'
|
|
|
|
echo
|
|
|
|
echo '--xsd Output xUnit XML schema for an integration server.'
|
|
|
|
echo
|
|
|
|
echo 'Go to http://www.urchin.sh for documentation on writing tests.'
|
|
|
|
echo
|
|
|
|
exit 0
|
2012-10-11 02:21:05 -04:00
|
|
|
}
|
2012-10-11 01:46:02 -04:00
|
|
|
|
2012-10-11 02:21:05 -04:00
|
|
|
urchin_go() {
|
2012-10-08 10:43:14 -04:00
|
|
|
echo Running tests
|
2012-10-11 01:10:43 -04:00
|
|
|
|
|
|
|
echo > "$logfile"
|
2012-10-10 20:43:13 -04:00
|
|
|
recurse "$1" 0
|
2012-10-11 01:10:43 -04:00
|
|
|
|
2012-10-08 10:43:14 -04:00
|
|
|
echo Done
|
2012-10-11 01:10:43 -04:00
|
|
|
echo $(grep -e 'passed$' "$logfile"|wc -l) tests passed.
|
|
|
|
echo $(grep -e 'failed$' "$logfile"|wc -l) tests failed.
|
2012-10-11 02:21:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
urchin_molly_guard() {
|
2012-10-11 01:46:02 -04:00
|
|
|
echo
|
|
|
|
echo 'The directory on which you are running urchin is not'
|
|
|
|
echo 'called "test", so I am not running in case that'
|
|
|
|
echo 'was an accident. Use the -f flag if you really want'
|
|
|
|
echo 'to run urchin on that directory.'
|
|
|
|
echo
|
|
|
|
exit 1
|
2012-10-11 02:21:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
FORCE=false
|
|
|
|
HELP=false
|
|
|
|
while [ $# -gt 0 ]
|
|
|
|
do
|
|
|
|
case "$1" in
|
|
|
|
-f) FORCE=true;;
|
|
|
|
-h) HELP=true;;
|
|
|
|
# --xsd) action=testsuite;;
|
|
|
|
# --) shift; break;;
|
|
|
|
-*) echo >&2 $USAGE
|
|
|
|
exit 1;;
|
|
|
|
*) break;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2012-10-11 02:34:20 -04:00
|
|
|
# Constants
|
|
|
|
logfile=$(readlink -f "$1/.urchin.log")
|
|
|
|
stdout_file=/tmp/urchin_stdout
|
|
|
|
|
2012-10-11 02:21:05 -04:00
|
|
|
# Help first
|
|
|
|
$HELP && urchin_help
|
|
|
|
|
|
|
|
# Verify argument for main stuff
|
|
|
|
[ "$#" = '1' ] && [ -d "$1" ] ||
|
|
|
|
( echo "$USAGE" && exit 1 )
|
|
|
|
|
|
|
|
# Run or present the Molly guard.
|
|
|
|
if echo "$(basename "$(readlink -f "$1")")" | grep test || $FORCE
|
|
|
|
then
|
|
|
|
urchin_go "$1"
|
|
|
|
else
|
|
|
|
urchin_molly_guard
|
2012-10-08 10:43:14 -04:00
|
|
|
fi
|