#!/bin/sh -e
oname=raster
pkg=r-cran-`echo $oname | tr '[A-Z]' '[a-z]'`

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
cp /usr/share/doc/$pkg/examples/vignettes/* $AUTOPKGTEST_TMP
find . -name "*.gz" -exec gunzip \{\} \;
for rnw in `ls *.[rRS]nw` ; do
rfile=`echo $rnw | sed 's/\.[rRS]nw/.R/'`
R --no-save <<EOT
  Stangle("$rnw")
  source("$rfile", echo=TRUE)
EOT
  echo "$rnw passed"
done
