#!/bin/sh
#
# Run syntax testcase and compare results.
#
# Jani Salonen <salojan@goto10.co>
#

export LC_ALL=C

# Temporary file for testcase result
#
_o="/tmp/$$.out"

# Check if diff --color works
#
_c="--color=always"

diff ${_c} /dev/null /dev/null > /dev/null 2>&1

if [ $? != 0 ]; then
	_c=""
fi

# Run testcases
#
ls tests/syntax/*.ano | while read a; do
	_a=$(echo "${a}" | sed -e 's|^.*/||' -e 's|\.ano$||')

	if [ ! -f "tests/syntax/${_a}.out" ]; then
		echo "${0}: Failed to find test result template for testcase ${_a}." 1>&2

		continue
	fi

	./build/ano -ds "${a}" > /dev/null 2> "${_o}"

	diff ${_c} \
		--side-by-side \
		--suppress-common-lines \
		"tests/syntax/${_a}.out" "${_o}"

	_r=$?

	# Check testcase result
	#
	rm -f "${_o}"

	if [ "${_r}" != 0 ]; then
		echo " ! Test case ${_a} failed."
	else
		echo " * Test case ${_a} passed."
	fi
done

#
exit 0
