75 lines
1.7 KiB
Bash
Executable File
75 lines
1.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
indent() {
|
|
level="$1"
|
|
printf "%$((2 * ${level}))s"
|
|
}
|
|
|
|
recurse() {
|
|
potential_test="$1"
|
|
indent_level="$2"
|
|
|
|
[ "$potential_test" = 'setup_dir' ] && return
|
|
[ "$potential_test" = 'teardown_dir' ] && return
|
|
[ "$potential_test" = 'setup' ] && return
|
|
[ "$potential_test" = 'teardown' ] && return
|
|
|
|
# stdout_file=$(mktemp)
|
|
stdout_file=/tmp/urchin_stdout
|
|
|
|
if [ -d "$potential_test" ]
|
|
then
|
|
(
|
|
indent $indent_level
|
|
echo " ${potential_test}"
|
|
cd "$potential_test"
|
|
[ -f setup_dir ] && [ -x setup_dir ] && ./setup_dir &>> $stdout_file
|
|
for test in *
|
|
do
|
|
[ -f setup ] && [ -x setup ] && ./setup &>> $stdout_file
|
|
|
|
# $2 instead of $indent_level so it doesn't clash
|
|
recurse "${test}" $(( $2 + 1 ))
|
|
|
|
[ -f teardown ] && [ -x teardown ] && ./teardown &>> $stdout_file
|
|
done
|
|
[ -f teardown_dir ] && [ -x teardown_dir ] && ./teardown_dir &>> $stdout_file
|
|
)
|
|
elif [ -x "$potential_test" ]
|
|
then
|
|
|
|
[ -f setup ] && [ -x setup ] && ./setup &>> $stdout_file
|
|
|
|
# Run the test
|
|
./"$potential_test" &>> $stdout_file
|
|
exit_code="$?"
|
|
|
|
[ -f teardown ] && [ -x teardown ] && ./teardown &>> $stdout_file
|
|
|
|
indent $indent_level
|
|
if [ "$exit_code" = '0' ]
|
|
then
|
|
# On success, print a '✓'
|
|
echo -ne '\033[32m✓ \033[0m'
|
|
echo "${potential_test}"
|
|
else
|
|
# On fail, print a red '✗'
|
|
echo -ne '\033[31m✗ \033[0m'
|
|
echo "${potential_test}"
|
|
cat $stdout_file
|
|
fi
|
|
rm $stdout_file
|
|
fi
|
|
}
|
|
|
|
if [ "$#" = '1' ] && [ -d "$1" ]
|
|
then
|
|
echo Running tests
|
|
recurse "$1" 0
|
|
echo
|
|
echo Done
|
|
else
|
|
echo "usage: $0 <test directory>"
|
|
echo 'Go to http://www.urchin.sh for documentation on writing tests.'
|
|
fi
|