i3-colors/tests/run.sh

78 lines
1.6 KiB
Bash
Raw Normal View History

2019-10-08 21:59:31 -04:00
#!/bin/bash
2019-10-09 20:35:36 -04:00
[ $# -ne 1 ] && { echo "Usage: $0 <run | break | verbose | reset>"; exit 1; }
2019-10-09 10:05:52 -04:00
##### Arguments #####
2019-10-08 21:59:31 -04:00
wai=$(dirname $(readlink -f $0))
out=$(mktemp)
2019-10-09 10:05:52 -04:00
[ "$1" == "break" ] && int=1 || int=0
2019-10-09 20:35:36 -04:00
[ "$1" == "verbose" ] && verbose=1 || verbose=0
[ "$1" == "reset" ] && reset=1 || reset=0
2019-10-09 10:05:52 -04:00
#####################
2019-10-08 21:59:31 -04:00
2019-10-09 10:05:52 -04:00
##### Utils Functions #####
2019-10-08 21:59:31 -04:00
passed(){
echo -e "$1 ===> \e[32mpassed :)\e[0m"
}
fail(){
echo -e "$1 ===> \e[5m\e[31mfail :(\e[0m"
}
2019-10-09 10:05:52 -04:00
clean(){
rm ${out}
}
##################### #####
2019-10-08 21:59:31 -04:00
##### Run Integration Tests #####
nb_pass=0
nb_fail=0
for test in $(find ${wai} -type f -name "test-*.sh")
do
test_name=$(basename $test)
2019-10-09 10:05:52 -04:00
expectations="${wai}/${test_name%.*}.out"
2019-10-09 20:35:36 -04:00
if [ $reset -eq 1 ]
then
bash ${test} > "${out}" 2>&1 # Run Test
cat "${out}" > "${expectations}"
continue
else
bash ${test} > "${out}" 2>&1 # Run Test
fi
2019-10-09 10:05:52 -04:00
diff_out=$(diff "${out}" "${expectations}")
2019-10-08 21:59:31 -04:00
2019-10-09 10:05:52 -04:00
if [ ! -z "${diff_out}" ]
2019-10-08 21:59:31 -04:00
then
fail "${test_name}"
nb_fail=$(( nb_fail + 1 ))
2019-10-09 20:35:36 -04:00
if [ $int -eq 1 ] || [ $verbose -eq 1 ]
2019-10-08 21:59:31 -04:00
then
echo "========== Diff =========="
2019-10-09 10:05:52 -04:00
echo -e "${diff_out}"
2019-10-09 20:35:36 -04:00
if [ $verbose -eq 0 ]
then
clean
exit 1
fi
2019-10-08 21:59:31 -04:00
fi
else
2019-10-09 08:00:34 -04:00
nb_pass=$(( nb_pass + 1 ))
2019-10-08 21:59:31 -04:00
passed "${test_name}"
fi
done
2019-10-09 10:05:52 -04:00
clean
2019-10-08 21:59:31 -04:00
#################################
2019-10-09 20:35:36 -04:00
if [ $reset -eq 0 ]
then
echo -e "\n===== STATS ====="
echo "${nb_pass} pass"
echo "${nb_fail} fails"
2019-10-09 21:27:31 -04:00
if [ ${nb_fail} -gt 0 ]
then
exit 1
fi
2019-10-09 20:35:36 -04:00
else
echo "Reset done."
fi