# Run tests
# We run ParseAll for each of the defined syntaxes, 
# and run all of the JUnit tests indicated by files called Test*.java
# (if JUnit is available).

JAVAC=@JAVAC@
JAVA=@JAVA@

HAVE_JUNIT=@HAVE_JUNIT@
LIBCLASSPATH=@LIBCLASSPATH@
#JTESTS=TestMisc TestDimensions
# the following is starting to be Clever (and therefore wicked)
JTESTS=$(shell ls Test*.java | sed s/.java//)
PARSERS=@PARSERLIST@
#PARSERS=$(shell ls ../gen/uk/me/nxg/unity/Parser_*.java | sed 's/.*_\([a-z]*\).java/\1/')


../../grammar/testcases-%.csv: ../../grammar/testcases.csv
	cd ../../grammar; make `basename $@`


build/%.class: %.java
	test -d build || mkdir build
	$(JAVAC) -encoding UTF8 -d build -cp ../unity.jar:$(LIBCLASSPATH) $<


check: build/ParseAll.class check-junit \
		$(patsubst %,../../grammar/testcases-%.csv,$(PARSERS))
	$(JAVA) -ea -cp build:../unity.jar ParseAll \
	  -t $(patsubst %,-p%,$(PARSERS)) \
	  ../../grammar/testcases-%.csv

# Run JUnit tests if JUnit is available; otherwise silently skip them
check-junit:
	if $(HAVE_JUNIT); then $(MAKE) run-junit; else :; fi

run-junit: build/RunTests.class $(patsubst %,build/%.class,$(JTESTS)) 
	$(JAVA) -cp build:../unity.jar:$(LIBCLASSPATH) RunTests $(JTESTS)

clean:
	rm -Rf build
