# 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=/usr/bin/javac
JAVA=/usr/bin/java

HAVE_JUNIT=:
LIBCLASSPATH=/checkouts/bitbucket.org/unity/lib/hamcrest-core-1.1.jar:/checkouts/bitbucket.org/unity/lib/icu4j-3.4.4.jar:/checkouts/bitbucket.org/unity/lib/iri-0.8.jar:/checkouts/bitbucket.org/unity/lib/jflex-1.4.3.jar:/checkouts/bitbucket.org/unity/lib/joda-time-1.6.2.jar:/checkouts/bitbucket.org/unity/lib/junit-4.10.jar:/checkouts/bitbucket.org/unity/lib/mrg-0.7.jar:/checkouts/bitbucket.org/unity/lib/xercesImpl-2.7.1.jar
#JTESTS=TestMisc TestDimensions
# the following is starting to be Clever (and therefore wicked)
JTESTS=$(shell ls Test*.java | sed s/.java//)
PARSERS=fits ogip cds vounits
#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
