2016-08-17 09:39:40 +00:00
|
|
|
|
#! /bin/bash
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
if [[ $# -lt 1 || $# -gt 2 ]] ; then
|
|
|
|
|
echo "Usage: $0 <prefix-path> [1]" 1>&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2016-08-17 21:31:15 +00:00
|
|
|
|
# Obtain the absolute path to the tests directory
|
|
|
|
|
pushd "$(dirname "$0")" &> /dev/null
|
|
|
|
|
readonly T=$(pwd)
|
|
|
|
|
popd &> /dev/null
|
2016-08-17 09:39:40 +00:00
|
|
|
|
export T
|
|
|
|
|
|
2016-08-17 21:31:15 +00:00
|
|
|
|
# Same for the nginx prefix directory
|
|
|
|
|
pushd "$1" &> /dev/null
|
|
|
|
|
readonly prefix=$(pwd)
|
|
|
|
|
popd &> /dev/null
|
2016-08-17 09:39:40 +00:00
|
|
|
|
|
|
|
|
|
dynamic=false
|
|
|
|
|
if [[ $# -gt 1 && $2 -eq 1 ]] ; then
|
|
|
|
|
dynamic=true
|
|
|
|
|
fi
|
|
|
|
|
readonly dynamic
|
|
|
|
|
|
|
|
|
|
declare -a t_pass=( )
|
|
|
|
|
declare -a t_fail=( )
|
|
|
|
|
|
|
|
|
|
for t in "$T"/*.test ; do
|
|
|
|
|
name="t/${t##*/}"
|
|
|
|
|
name=${name%.test}
|
|
|
|
|
printf "${name} ... "
|
|
|
|
|
errfile="${name}.err"
|
|
|
|
|
outfile="${name}.out"
|
|
|
|
|
shfile="${name}.sh"
|
|
|
|
|
cat > "${shfile}" <<-EOF
|
|
|
|
|
readonly DYNAMIC=${dynamic}
|
2016-08-17 21:31:15 +00:00
|
|
|
|
readonly TESTDIR='$T'
|
|
|
|
|
readonly PREFIX='${prefix}'
|
2016-08-17 10:35:49 +00:00
|
|
|
|
$(< "$T/preamble")
|
2016-08-17 09:39:40 +00:00
|
|
|
|
$(< "$t")
|
|
|
|
|
EOF
|
|
|
|
|
if bash -e "${shfile}" > "${outfile}" 2> "${errfile}" ; then
|
|
|
|
|
t_pass+=( "${name}" )
|
|
|
|
|
printf '[1;32mpassed[0;0m\n'
|
|
|
|
|
else
|
|
|
|
|
t_fail+=( "${name}" )
|
|
|
|
|
printf '[1;31mfailed[0;0m\n'
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
for name in "${t_fail[@]}" ; do
|
2016-08-18 16:19:11 +00:00
|
|
|
|
echo
|
|
|
|
|
printf '[1m===[0m %s.out\n' "${name}"
|
2016-08-17 09:39:40 +00:00
|
|
|
|
cat "${name}.out"
|
2016-08-18 16:19:11 +00:00
|
|
|
|
echo
|
|
|
|
|
printf '[1m===[0m %s.err\n' "${name}"
|
2016-08-17 09:39:40 +00:00
|
|
|
|
cat "${name}.err"
|
2016-08-18 16:19:11 +00:00
|
|
|
|
echo
|
2016-08-17 09:39:40 +00:00
|
|
|
|
done
|
|
|
|
|
|
2016-08-18 16:19:11 +00:00
|
|
|
|
printf '[1m===[0m passed/failed/total: [1;32m%d[0;0m/[1;31m%d[0;0m/[1m%d[0m\n' \
|
2016-08-17 09:39:40 +00:00
|
|
|
|
${#t_pass[@]} ${#t_fail[@]} $(( ${#t_pass[@]} + ${#t_fail[@]} ))
|
|
|
|
|
|
|
|
|
|
if [[ ${#t_fail[@]} -gt 0 ]] ; then
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|