#!/bin/sh -ex

pkg=r-cran-pscbs
if [ "$AUTOPKGTEST_TMP" = "" ] ; then
  AUTOPKGTEST_TMP=`mktemp -d /tmp/${pkg}-test.XXXXXX`
fi
cd $AUTOPKGTEST_TMP
cp -a /usr/share/doc/${pkg}/tests/* $AUTOPKGTEST_TMP
find . -name "*.gz" -exec gunzip \{\} \;
export LC_ALL=C

hostarch=$(dpkg-architecture -qDEB_HOST_ARCH)
# Ignore a tests for arhf architecture which works on porter box, but not on debci infrastructure
if [ "$hostarch" = "armhf" ] ; then
  rm -f *futures.R
fi

for htest in `ls *.R | sed 's/\.R$//'` ; do
  echo "Begin test ${htest}"
  exitcode=0
  R CMD BATCH ${htest}.R || exitcode=$?
  cat ${htest}.Rout
  if [ $exitcode != 0 ]; then
	echo "Exiting with code $exitcode"
	exit $exitcode
  fi
  echo "Test ${htest} passed"
  echo "$exitcode"
done
rm -f $AUTOPKGTEST_TMP/*
