#!/bin/sh
# Test runner

usage() {
	echo "Usage: $0 <test>"
}

run() {
	rm -rf ~/.angband/Test

	test="$1"
	echo -n "Running: $test... "
	../src/angband -mtest < "$test/input" > "$test/run.out"
	if [ -x "$test/matcher" ]; then
		"$test/matcher" "$test"
	else
		diff "$test/run.out" "$test/output" >/dev/null 2>/dev/null
	fi
	result=$?
	if [ $result -eq 0 ]; then
		printf "\033[01;32mPassed\033[00m\n"
	else
		printf "\033[01;31mFailed\033[00m\n"
	fi
	return $result
}

if [ $# -lt 1 ]; then
	usage
	exit 1
fi

run "$@"
