#!/bin/sh

pkg=r-cran-backports

if [ "$AUTOPKGTEST_TMP" = "" ] ; then
  AUTOPKGTEST_TMP=$(mktemp -d /tmp/${pkg}-test.XXXXXX)
  trap 'rm -rf $AUTOPKGTEST_TMP' 0 INT QUIT ABRT PIPE TERM
fi

cd "$AUTOPKGTEST_TMP" || exit

cp -a /usr/share/doc/${pkg}/tests/* "$AUTOPKGTEST_TMP"

export LC_ALL=C
for test in *R
do
  echo "Testing ${test}"
  R CMD BATCH "${test}" || { cat "${test}out" ; echo "Test ${test} failed" ; exit 1 ; }
  echo "Test ${test} passed"
  rm -f "${test}out" .RData
done
