#!/bin/sh
# Compile upstream's tests with the installed compilers against the
# installed jars, and run them.
set -eu
T=${AUTOPKGTEST_TMP:-$(mktemp -d)}
J=/usr/share/java
debian/build-info "$(pwd)/tests/shared/src/main" "$T/gen"
for v in 2.13 3; do
	if [ $v = 3 ]; then opts="-pagewidth 80"; else opts=""; fi
	jars=$J/munit-$v.jar:$J/munit-diff-$v.jar:$J/munit-junit-interface.jar
	cp=$jars:$J/scala-reflect-2.13.jar:$J/junit4.jar:$J/sbt-test-interface.jar
	mkdir -p "$T/$v"
	find tests/shared/src tests/jvm/src "$T/gen/$v" -name '*.scala' \
		| LC_ALL=C sort > "$T/$v.files"
	# shellcheck disable=SC2086
	scalac-$v -nowarn $opts -d "$T/$v" -cp "$cp" @"$T/$v.files"
	debian/run-upstream-tests $v "$T/$v:$jars"
done
