#!/bin/sh -e

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

if [ $(dpkg-architecture -qDEB_HOST_ARCH_BITS) -eq 32 ] ; then
    echo "Test data are to big for 32bit architectures thus no testing is done"
    jellyfish --help
    exit 0
fi

cd $AUTOPKGTEST_TMP
mkdir tests
cp -a /usr/share/doc/jellyfish-examples/examples/* tests
mv tests/compat.sh ./
sed -i "s#DIR=../bin#DIR=/usr/lib/${pkg}/bin#" compat.sh
echo "#define HAVE_HTSLIB" > config.h
tests/generate_sequence.sh
sh tests/parallel_hashing.sh
sh tests/merge.sh
sh tests/bloom_filter.sh
echo "If you have a *really* powerful machine you can run this *really* big test by prepending"
echo "  'BIG=1' "
echo "before the following line"
sh tests/big.sh || true
sh tests/subset_hashing.sh
##############################################################################################
# It seems the following failures in the following test are planed ...
#
# $ jellyfish count -t 2 -g multi_file_fail_cmds -G 2 -C -m 15 -s 2M -o multi_file_fail.jf
# Command 'false' exited with error status 1
# Some generator commands failed
# $ jellyfish count -t 2 -C -m 15 -s 2M -o multi_file_fail.jf non_existent_sequence.fa
# terminate called after throwing an instance of 'std::runtime_error'
#   what():  Can't open file 'non_existent_sequence.fa'
# Aborted
#
sh tests/multi_file.sh
#############################################################################################
sh tests/bloom_counter.sh
sh tests/large_key.sh
sh tests/sam.sh
bash tests/small_mers.sh
/usr/lib/jellyfish/bin/test_all
