#!/bin/sh
# Compile upstream's utest suites with the installed compilers against the
# installed jars and run them, as debian/rules does at build time.
set -eu
T=${AUTOPKGTEST_TMP:-$(mktemp -d)}
J=/usr/share/java
for v in 2.13 3; do
	CP=$J/fastparse-$v.jar:$J/sourcecode-$v.jar:$J/geny-$v.jar:$J/utest-$v.jar
	CP=$CP:$J/scala-collection-compat_$v.jar:$J/sbt-test-interface.jar
	OPT=-nowarn
	if [ $v = 2.13 ]; then CP=$J/scala-reflect-2.13.jar:$CP; else OPT="$OPT -source:3.4"; fi
	mkdir -p "$T/$v"
	find fastparse/test/src fastparse/test/src-2.12+ -name '*.scala' | LC_ALL=C sort > "$T/$v.files"
	echo debian/tests/RunTests.scala >> "$T/$v.files"
	scalac-$v $OPT -d "$T/$v" -cp "$CP" @"$T/$v.files"
	java -cp "$J/scala-library-$v.jar:$CP:$T/$v:fastparse/test/resources" \
		debian.utest.RunTests utest.runner.Framework "$T/$v"
done
