#!/bin/sh -e

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

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

# Somehow 0 byte files are not propageted into the package :-(
for zerobytefile in $(find tests -size 0) ; do
  mkdir -p $AUTOPKGTEST_TMP/$(dirname $zerobytefile)
  touch "$AUTOPKGTEST_TMP/$zerobytefile"
done

cd $AUTOPKGTEST_TMP
cd tests

find . -name "*.gz" -exec gunzip \{\} \;

R --no-save < testthat.R
