#!/bin/sh -e

if [ "$ADTTMP" = "" ] ; then
  ADTTMP=`mktemp -d /tmp/bedtools-test.XXXXXX`
  trap "rm -rf $ADTTMP" 0 INT QUIT ABRT PIPE TERM
fi

# Copy test suite there
cp -a /usr/share/bedtools/test $ADTTMP

# Link to genomes files
cd $ADTTMP
ln -s /usr/share/bedtools/genomes

# Enter the directory and run the tests
cd $ADTTMP/test
DATA=/usr/share/bedtools/data BT=/usr/bin/bedtools sh test.sh | tee test.sh.output

# Did it fail ?
TESTFAILED=0
grep -q fail test.sh.output && TESTFAILED=1

exit $TESTFAILED
