#!/bin/sh
# Run the upstream tests of the library against the jar given as $1. They
# are JUnit 4 tests that drive Jupiter sample tests through the interface.
set -e

JAR=${1:-/usr/share/java/jupiter-interface.jar}
WORK=$(mktemp -d)
trap 'rm -rf "$WORK"' EXIT

J=/usr/share/java
TESTS=src/library/src/test/java
CP=$JAR:$J/sbt-test-interface.jar
for j in junit-platform-launcher junit-platform-engine junit-platform-commons \
	junit-jupiter-engine junit-jupiter-api junit-jupiter-params \
	junit-vintage-engine junit-platform-suite-api junit-platform-suite-engine \
	junit-platform-suite-commons opentest4j apiguardian-api junit4 hamcrest \
	mockito-core byte-buddy byte-buddy-agent objenesis; do
	CP=$CP:$J/$j.jar
done

javac --release 17 -encoding UTF-8 -nowarn -cp "$CP" -d "$WORK" \
	$(find $TESTS -name '*.java' | LC_ALL=C sort)

CLASSES=$(cd $TESTS && grep -rl '^import org.junit.Test;' --include='*.java' . \
	| sed -e 's|^\./||' -e 's|\.java$||' -e 's|/|.|g' | LC_ALL=C sort)

java -cp "$WORK:$CP" org.junit.runner.JUnitCore $CLASSES
