#!/bin/sh -e

debname=r-cran-hdf5r
# 77 = skip on armel, #1104158
dpkg --print-architecture | grep -q -e armel && exit 77

if [ "$AUTOPKGTEST_TMP" = "" ] ; then
    AUTOPKGTEST_TMP=`mktemp -d /tmp/${debname}-test.XXXXXX`
    trap "rm -rf $AUTOPKGTEST_TMP" 0 INT QUIT ABRT PIPE TERM
fi
cd $AUTOPKGTEST_TMP
cp -a /usr/share/doc/$debname/tests $AUTOPKGTEST_TMP
gunzip -r *
cd tests

hostarch=$(dpkg-architecture -qDEB_HOST_ARCH)
# Ignore single test for all architectures except amd64
if [ "$hostarch" != "amd64" ] ; then
  sed -i -e '/^test_that."Datatype conversion with 64bit"/,/^})/d' testthat/test-64bit_support.R
  sed -i -e '/^test_that."Convert H5T_ENUM works"/,/^})/d' testthat/test-convert.R
  if [ "$hostarch" = "i386" -o "$hostarch" = "armhf" ] ; then
    cd testthat
    rm -f test-64bit_support.R \
          test-convert.R \
          test-h5a.R \
          test-h5d.R \
          test-h5p.R \
          test-high_level_UI.R \
          test-reference.R \
          test-zzz-Attribute.R \
          test-zzz-DataSet-extend.R \
          test-zzz-DataSet-IO-NA.R \
          test-zzz-DataSet-IO.R \
          test-zzz-DataSet.R \
          test-zzz-DataSet-scalar.R \
          test-zzz-DataSet-Select-Subset.R \
          test-zzz-H5File-Subset.R \
          test-zzz-H5Group.R \
          test-zzz-io.R \
          test-zzz-vlen.R
    cd ..
  fi
  if [ "$hostarch" = "i386" ] ; then
    rm -f testthat/test-h5t.R
  fi
fi

for testfile in *.R; do
    echo "BEGIN TEST $testfile"
    LC_ALL=C.UTF-8 R --no-save < $testfile
done
