2012-10-09 15:45:20 +00:00
|
|
|
#!/bin/bash
|
2012-10-04 11:24:03 +00:00
|
|
|
|
2012-10-04 11:29:34 +00:00
|
|
|
recurse() {
|
|
|
|
potential_test="$1"
|
2012-10-10 18:40:49 +00:00
|
|
|
|
|
|
|
[ potential_test = 'setup_dir' ] && return
|
|
|
|
[ potential_test = 'teardown_dir' ] && return
|
|
|
|
[ potential_test = 'setup' ] && return
|
|
|
|
[ potential_test = 'teardown' ] && return
|
|
|
|
|
2012-10-04 11:29:34 +00:00
|
|
|
if [ -d "$potential_test" ]
|
|
|
|
then
|
|
|
|
(
|
|
|
|
cd "$potential_test"
|
2012-10-10 18:25:44 +00:00
|
|
|
[ -f setup_dir ] && . ./setup_dir
|
2012-10-08 14:16:49 +00:00
|
|
|
for test in *
|
2012-10-08 12:50:48 +00:00
|
|
|
do recurse "${test}"
|
|
|
|
done
|
2012-10-10 18:25:44 +00:00
|
|
|
[ -f teardown_dir ] && [ -x teardown_dir ] && ./teardown_dir
|
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-09 15:45:20 +00:00
|
|
|
#stdout_file=$(mktemp)
|
|
|
|
stdout_file=/tmp/urchin_stdout
|
2012-10-10 18:25:44 +00:00
|
|
|
|
|
|
|
# Run the test
|
2012-10-10 18:30:34 +00:00
|
|
|
[ -f setup ] && . ./setup &>> $stdout_file
|
|
|
|
./"$potential_test" &>> $stdout_file
|
2012-10-10 18:40:49 +00:00
|
|
|
exit_code="$?"
|
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-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 '✓'
|
2012-10-09 15:45:20 +00:00
|
|
|
echo -ne '\033[32m✓ \033[0m'
|
|
|
|
echo "${potential_test}"
|
2012-10-04 11:29:34 +00:00
|
|
|
else
|
2012-10-10 18:25:44 +00:00
|
|
|
# On fail, print a red '✗'
|
2012-10-09 15:45:20 +00:00
|
|
|
echo -ne '\033[31m✗ \033[0m'
|
|
|
|
echo "${potential_test}"
|
|
|
|
cat $stdout_file
|
2012-10-04 11:29:34 +00:00
|
|
|
fi
|
2012-10-09 15:45:20 +00:00
|
|
|
rm $stdout_file
|
2012-10-04 11:29:34 +00:00
|
|
|
fi
|
|
|
|
}
|
2012-10-04 16:43:49 +00:00
|
|
|
|
2012-10-10 10:09:18 +00:00
|
|
|
if [ "$#" = '0' ]
|
2012-10-08 14:43:14 +00:00
|
|
|
then
|
|
|
|
echo Running tests
|
|
|
|
recurse .
|
|
|
|
echo
|
|
|
|
echo Done
|
|
|
|
else
|
|
|
|
echo 'Run `urchin` without arguments from a directory containing urchin tests.'
|
|
|
|
echo 'Go to http://www.urchin.sh for documentation on writing tests.'
|
|
|
|
fi
|