#!/bin/sh

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

prepare
debug_tests

cd "$AUTOPKGTEST_TMP"

# exclude failing tests

# Error:EOPNOTSUPP likely caused by autopkgtest environment
echo 'exclude :test_cp_r_symlink_preserve, "fails in autopkgtests"' >> test/mri/excludes/TestFileUtils.rb

# Unknown cause, fails systematically to raise TypeError
mkdir test/mri/excludes/TestDigest
echo 'exclude :test_initialize_copy_md5_rmd160, "fails in autopkgtests"' >> test/mri/excludes/TestDigest/TestInitCopy.rb

# Causes the test to hang/timeout for an unknown reason
echo 'exclude :test_get__break, "fails in autopkgtests"' >> test/mri/excludes/TestNetHTTP_v1_2.rb

# skip failing tests on specific architectures
if [ "$(dpkg-architecture -qDEB_BUILD_ARCH)" = "arm64" ]; then
    echo 'exclude :test_failed_path, "fails in autopkgtests"' >> test/mri/excludes/TestIO_Console.rb
elif [ "$(dpkg-architecture -qDEB_BUILD_ARCH)" = "armel" ] || \
     [ "$(dpkg-architecture -qDEB_BUILD_ARCH)" = "armhf" ]; then
    { echo 'exclude :test_cp, "fails in autopkgtest"';
      echo 'exclude :test_cp_r, "fails in autopkgtest"';
      echo 'exclude :test_uptodate?, "fails in autopkgtest"';
      echo 'exclude :test_install, "fails in autopkgtest"';
    } >> test/mri/excludes/TestFileUtils.rb
    echo 'exclude :test_failed_path, "fails in autopkgtests"' >> test/mri/excludes/TestIO_Console.rb
    echo 'exclude :test_utime, "fails in autopkgtests"' >> test/mri/excludes/TestPathname.rb
elif [ "$(dpkg-architecture -qDEB_BUILD_ARCH)" = "ppc64el" ]; then
    { echo 'exclude :test_cooked, "fails in autopkgtests"';
      echo 'exclude :test_raw, "fails in autopkgtests"';
      echo 'exclude :test_raw_minchar, "hangs in autopkgtests"';
      echo 'exclude :test_raw_timeout, "hangs in autopkgtests"';
      echo 'exclude :test_raw_intr, "hangs in autopkgtests"';
      echo 'exclude :test_winsize, "fails in autopkgtests"';
    } >> test/mri/excludes/TestIO_Console.rb
elif [ "$(dpkg-architecture -qDEB_BUILD_ARCH)" = "s390x" ]; then
    echo 'exclude :test_uptodate?, "fails in autopkgtest"' >> test/mri/excludes/TestFileUtils.rb
    echo 'exclude :test_failed_path, "fails in autopkgtests"' >> test/mri/excludes/TestIO_Console.rb
    echo 'exclude :test_utime, "fails in autopkgtests"' >> test/mri/excludes/TestPathname.rb
fi

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