#!/bin/sh

set -e

# This is a basic test runner for shell script tests
# it just searches for all test_ scripts under the tests
# folder, and run them.

echo "Running shell script unit tests..."

CURDIR=$(pwd)
SUCCESS=yes
CNT=0
for i in $(find tests -type f -iname 'test_*') ; do
	DIRNAME=$(dirname $i)
	BASENAME=$(basename $i)
	cd ${DIRNAME}
	echo -n $i" ... "
	if ./${BASENAME} ; then
		echo "OK"
	else
		SUCCESS=no
		echo "FAILED"
	fi
	cd ${CURDIR}
	CNT=$(( ${CNT} + 1 ))
done

if [ "${SUCCESS}" = "yes" ] ; then
	echo "Successfully ran ${CNT} tests :)"
	exit 0
else
	echo "Failure while running unit tests :("
	exit 1
fi
