#!/bin/sh -e

pkgname=diffobj
debname=r-cran-diffobj

filter() {
    grep -v -e '^R version' \
        -e '^Copyright (C)' \
        -e '^R : Copyright 20' \
        -e '^R Under development' \
        -e '^Version 2.0' \
        -e '^Platform:' \
       $1 | \
    sed -e '/^> *proc\.time()$/,$d' \
        -e '/^  Natural language support but running in an English locale$/,+1d'
}

if [ "$AUTOPKGTEST_TMP" = "" ] ; then
    AUTOPKGTEST_TMP=`mktemp -d /tmp/${debname}-test.XXXXXX`
    trap "rm -rf $AUTOPKGTEST_TMP" 0 INT QUIT ABRT PIPE TERM
fi
cd $AUTOPKGTEST_TMP
cp -a /usr/share/doc/$debname/tests/* $AUTOPKGTEST_TMP
gunzip -r *

# Remove one test which fails due to un-ruly spacing
rm -f test-diffPrint.R

# Since diff is already being done in autopkgtests, remove zz-test-check.R as well although that is harmless
rm -f zz-test-check.R

for htest in `ls *.R | sed 's/\.R$//'` ; do
   echo "Begin testing ${htest}.R"
   LC_ALL=C R --no-save < ${htest}.R 2>&1 | tee -a ${htest}.Rout
   if [ -e ${htest}.Rout.save ]; then
	filter ${htest}.Rout.save > ${htest}.Rout.save_
	filter ${htest}.Rout > ${htest}.Rout_
	diff -u --ignore-all-space ${htest}.Rout.save_ ${htest}.Rout_
   fi
   echo "PASS"
done
