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

if [ "$AUTOPKGTEST_TMP" = "" ] ; then
  AUTOPKGTEST_TMP=`mktemp -d /tmp/${pkg}-test.XXXXXX`
fi
cd $AUTOPKGTEST_TMP
cp -a /usr/share/doc/$pkg/examples/vignettes .
gunzip vignettes/*.gz
mkdir R
cp /usr/lib/R/site-library/Epi/doc/simLexis.R R/.
cd vignettes
for rnw in `ls *.[rR]nw` ; do
rfile=`echo $rnw | sed 's/\.[rR]nw/.R/'`
if [ "$rfile" = "simLexis.R" -o "$rfile" = "yll.R" ] ; then
    >&2 echo "Vignete $rnw runs infinite loop - ignoring this for the test"
    continue
fi
R --no-save <<EOT
  Stangle("$rnw")
  source("$rfile", echo=TRUE)
EOT
done
rm -rf *
