#!/bin/sh

set -ex

src="$(pwd)"
test="$AUTOPKGTEST_TMP/test"

# Copy just what's needed to test to ensure we're not testing the
# source tree.  This may need adjustment if upstream changes.
mkdir "$test"
cp -a --parents readme.txt src/script test "$test"

cd "$test"

cp="/usr/share/java/clojure.jar"
cp="$cp:/usr/share/java/test.check.jar"
cp="$cp:/usr/share/java/test.generative.jar"
cp="$cp:/usr/share/java/tools.namespace.jar"
cp="$cp:test/java"
cp="$cp:test"

# See build.xml compile-tests target
java -cp "$cp" \
     -Dclojure.compile.path=test \
     clojure.lang.Compile \
     clojure.test-clojure.protocols.examples \
     clojure.test-clojure.proxy.examples \
     clojure.test-clojure.genclass.examples \
     clojure.test-clojure.compilation.load-ns \
     clojure.test-clojure.annotations

for java in $(find test -name "*.java"); do
    javac -cp "$cp" "$java"
done

# See build.xml test-example target
ex='#{clojure.test-clojure.compilation clojure.test-clojure.ns-libs-load-later}'

java -cp "$cp" \
     -Dclojure.test-clojure.exclude-namespaces="$ex" \
     clojure.main src/script/run_test.clj
