#!/bin/sh
# Run upstream's test suites (the classes of tests/*/src/test, except the
# abstract ones) with JUnit, from the top of the source tree as sbt does.
# Usage: run-upstream-tests BINVER CLASSPATH
set -eu
J=/usr/share/java
cp=$2:$J/scala-library-$1.jar:$J/scala-reflect-2.13.jar
cp=$cp:$J/junit4.jar:$J/hamcrest.jar:$J/sbt-test-interface.jar
suites=$(for f in tests/shared/src/test/scala/munit/*.scala \
		tests/jvm/src/test/scala/munit/*.scala; do
	c=$(basename "$f" .scala)
	grep -q "^abstract class $c" "$f" || echo "munit.$c"
done | LC_ALL=C sort)
echo "Scala $1: running $(echo "$suites" | wc -l) suites"
# shellcheck disable=SC2086
java -cp "$cp" org.junit.runner.JUnitCore $suites
