#!/bin/sh -e

debname=r-cran-clock

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

# Workaround for #1028111
# it is not really closing the bug but enable the package migrating to testing
# Hope issue
#   https://github.com/r-lib/clock/issues/312
# will be close by upstream
hostarch=$(dpkg-architecture -qDEB_HOST_ARCH)
# Ignore single test for i386 architecture.  This is a workaround for bug #1024828 of r-cran-igraph
if [ "$hostarch" = "i386" -o "$hostarch" = "armel" -o "$hostarch" = "armhf" ] ; then
  sed -i -e '152d' -e '151d' testthat/test-posixt.R
fi

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

