#!/bin/sh

. "$(dirname $0)/common.sh"

prepare

cd "$AUTOPKGTEST_TMP"

# extra java libs required
mkdir test/target
ln -s /usr/share/java/junit4.jar test/target/junit.jar
ln -s /usr/share/java/jakarta-annotation-api.jar test/target/annotation-api.jar
ln -s /usr/share/java/jarjar.jar test/target/jarjar.jar

# compile a few test dependencies
gcc test/jruby/testapp/testapp.c -o test/jruby/testapp/testapp
javac -cp lib/jruby.jar:test/target/junit.jar:test/target/annotation-api.jar -d test/target/test-classes \
    test/org/jruby/test/*.java \
    test/org/jruby/javasupport/test/*.java \
    test/org/jruby/javasupport/test/*/*.java \
    test/*.java

# some test cases look for these specific files
cp "$OLDPWD/pom.xml" .
cp bin/jruby bin/jruby.sh

# when $TMPDIR is /tmp and $PWD is under there
# it causes the test_jrubyc.rb/test_target test case to fail
TMPDIR="$(mktemp -d)"
export TMPDIR

# skip failing tests on specific architectures
if [ "$(dpkg-architecture -qDEB_BUILD_ARCH)" = "armel" ] || \
   [ "$(dpkg-architecture -qDEB_BUILD_ARCH)" = "armhf" ]; then
  sed -i "/def test_file_open_utime/a    omit 'skip for autopkgtest'" test/jruby/test_file.rb
  sed -i "/def test_file_utime_nil/a    omit 'skip for autopkgtest'" test/jruby/test_file.rb
  sed -i "/def test_file_mtime_after_fileutils_touch/a    omit 'skip for autopkgtest'" test/jruby/test_file.rb
elif [ "$(dpkg-architecture -qDEB_BUILD_ARCH)" = "ppc64el" ]; then
  sed -i "/def test_premature_close_raises_appropriate_errors/a    omit 'skip for autopkgtest'" test/jruby/test_io.rb
elif [ "$(dpkg-architecture -qDEB_BUILD_ARCH)" = "s390x" ]; then
  sed -i "/def test_file_open_utime/a    omit 'skip for autopkgtest'" test/jruby/test_file.rb
  sed -i "/def test_file_utime_nil/a    omit 'skip for autopkgtest'" test/jruby/test_file.rb
fi


# run the rspec testsuite
jruby -S rake test:jruby
