#! /bin/bash

declare -i TESTS=0
declare -i ERRORS=0
for TEST in *; do
	if [ -d $TEST ]; then
		[[ -f $TEST/forbidden ]] && if [ "$(egrep -f $TEST/regexps $TEST/forbidden | wc -l)" != "$(wc -l < $TEST/forbidden)" ]; then
			echo "$TEST failed to match all forbidden cases"
			ERRORS+=1
		fi
		[[ -f $TEST/allowed ]] && if [ "$(egrep -f $TEST/regexps $TEST/allowed | wc -l)" != "0" ]; then
			echo "$TEST detected an allowed case as forbidden"
			ERRORS+=1
		fi
		TESTS+=1
	fi
done
if [ $ERRORS == 0 ]; then
	echo "All $TESTS rules passed their tests"
else
	echo "$ERRORS errors were found during the rule tests"
fi
exit $ERRORS
