urchin/urchin

132 lines
2.9 KiB
Plaintext
Raw Normal View History

#!/bin/bash
2012-10-04 11:24:03 +00:00
2012-10-11 05:15:48 +00:00
stdout_file=/tmp/urchin_stdout
2012-10-11 00:43:13 +00:00
indent() {
level="$1"
printf "%$((2 * ${level}))s"
}
2012-10-04 11:29:34 +00:00
recurse() {
potential_test="$1"
2012-10-11 00:43:13 +00:00
indent_level="$2"
2012-10-10 18:40:49 +00:00
2012-10-10 18:43:41 +00:00
[ "$potential_test" = 'setup_dir' ] && return
[ "$potential_test" = 'teardown_dir' ] && return
[ "$potential_test" = 'setup' ] && return
[ "$potential_test" = 'teardown' ] && return
2012-10-10 18:40:49 +00:00
2012-10-11 05:15:48 +00:00
echo > "$stdout_file"
2012-10-11 00:31:18 +00:00
2012-10-04 11:29:34 +00:00
if [ -d "$potential_test" ]
then
(
2012-10-11 00:43:13 +00:00
indent $indent_level
echo " ${potential_test}"
2012-10-04 11:29:34 +00:00
cd "$potential_test"
2012-10-11 00:31:18 +00:00
[ -f setup_dir ] && [ -x setup_dir ] && ./setup_dir &>> $stdout_file
2012-10-08 14:16:49 +00:00
for test in *
2012-10-11 00:31:18 +00:00
do
[ -f setup ] && [ -x setup ] && ./setup &>> $stdout_file
2012-10-11 00:43:13 +00:00
# $2 instead of $indent_level so it doesn't clash
recurse "${test}" $(( $2 + 1 ))
2012-10-11 00:31:18 +00:00
[ -f teardown ] && [ -x teardown ] && ./teardown &>> $stdout_file
2012-10-08 12:50:48 +00:00
done
2012-10-11 00:31:18 +00:00
[ -f teardown_dir ] && [ -x teardown_dir ] && ./teardown_dir &>> $stdout_file
2012-10-11 05:17:20 +00:00
echo
2012-10-04 11:29:34 +00:00
)
2012-10-08 12:59:14 +00:00
elif [ -x "$potential_test" ]
2012-10-04 11:29:34 +00:00
then
2012-10-10 18:25:44 +00:00
2012-10-10 23:46:58 +00:00
[ -f setup ] && [ -x setup ] && ./setup &>> $stdout_file
2012-10-10 19:47:21 +00:00
2012-10-10 18:25:44 +00:00
# Run the test
2012-10-10 18:30:34 +00:00
./"$potential_test" &>> $stdout_file
2012-10-10 18:40:49 +00:00
exit_code="$?"
2012-10-10 19:47:21 +00:00
2012-10-10 18:30:34 +00:00
[ -f teardown ] && [ -x teardown ] && ./teardown &>> $stdout_file
2012-10-10 18:25:44 +00:00
2012-10-11 00:43:13 +00:00
indent $indent_level
2012-10-10 18:40:49 +00:00
if [ "$exit_code" = '0' ]
2012-10-04 11:29:34 +00:00
then
2012-10-10 18:25:44 +00:00
# On success, print a '✓'
echo -ne '\033[32m✓ \033[0m'
echo "${potential_test}"
2012-10-11 05:10:43 +00:00
echo "${potential_test} passed" >> "$logfile"
2012-10-04 11:29:34 +00:00
else
2012-10-10 18:25:44 +00:00
# On fail, print a red '✗'
echo -ne '\033[31m✗ \033[0m'
echo "${potential_test}"
2012-10-11 05:10:43 +00:00
echo "${potential_test} failed" >> "$logfile"
2012-10-10 23:46:58 +00:00
cat $stdout_file
2012-10-04 11:29:34 +00:00
fi
rm $stdout_file
2012-10-04 11:29:34 +00:00
fi
}
2012-10-04 16:43:49 +00:00
2012-10-11 05:46:02 +00:00
USAGE="usage: $0 <test directory>"
FORCE=false
2012-10-11 05:52:29 +00:00
HELP=false
2012-10-11 05:46:02 +00:00
while [ $# -gt 0 ]
do
case "$1" in
-f) FORCE=true;;
2012-10-11 05:52:29 +00:00
-h) HELP=true;;
2012-10-11 05:46:02 +00:00
# --xsd) action=testsuite;;
# --) shift; break;;
-*) echo >&2 $USAGE
exit 1;;
*) break;;
esac
shift
done
2012-10-11 05:52:29 +00:00
if $HELP
then
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
fi
2012-10-11 05:46:02 +00:00
# Check
2012-10-10 19:51:06 +00:00
if [ "$#" = '1' ] && [ -d "$1" ]
2012-10-11 05:46:02 +00:00
then
sleep 0s
else
echo "$USAGE"
exit 1
fi
# Go
2012-10-11 06:02:06 +00:00
if echo $(basename "$(readlink -f "$1")") | grep test || $FORCE
2012-10-08 14:43:14 +00:00
then
echo Running tests
2012-10-11 05:10:43 +00:00
logfile=$(readlink -f "$1/.urchin.log")
echo > "$logfile"
2012-10-11 00:43:13 +00:00
recurse "$1" 0
2012-10-11 05:10:43 +00:00
2012-10-08 14:43:14 +00:00
echo Done
2012-10-11 05:10:43 +00:00
echo $(grep -e 'passed$' "$logfile"|wc -l) tests passed.
echo $(grep -e 'failed$' "$logfile"|wc -l) tests failed.
2012-10-08 14:43:14 +00:00
else
2012-10-11 05:46:02 +00: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-08 14:43:14 +00:00
fi