#!/bin/bash
set -e

pkg=mmseqs2

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

cp -r /usr/lib/${pkg}/test "${AUTOPKGTEST_TMP}"
cp -r /usr/share/doc/${pkg}/example-data "${AUTOPKGTEST_TMP}"

# Build some data for the test binaries as prerequisites
cd "${AUTOPKGTEST_TMP}"/example-data
gunzip *.gz

mmseqs createdb DB.fasta DB
mmseqs createindex DB tmp

cd "${AUTOPKGTEST_TMP}"/test

# Notice: Some tests have been excluded as they have user directories hard-coded.
# ... Maybe a patch soon to rectify this.

echo "Invoking test_alignment"
./test_alignment
echo "Invoking test_alignmentraceback"
./test_alignmenttraceback
echo "Invoking test_alp"
./test_alp
echo "Invoking test_backtracetranslator"
./test_backtracetranslator
echo "Invoking test_compositionbias"
./test_compositionbias
echo "Invoking test_kmergenerator"
./test_kmergenerator
echo "Invoking test_kmernucl"
./test_kmernucl
echo "Invoking test_kmerscore"
./test_kmerscore
echo "Invoking test_ksw2"
./test_ksw2
echo "Invoking test_kwaymerge"
./test_kwaymerge
echo "Invoking test_multiplealignment"
./test_multiplealignment
echo "Invoking test_profilealignment"
./test_profilealignment
echo "Invoking test_profilestates"
./test_profilestates
echo "Invoking test_pssm"
./test_pssm
echo "Invoking test_pssmprune"
./test_pssmprune
echo "Invoking test_reducematrix"
./test_reducematrix
echo "Invoking test_sequenceindex"
./test_sequenceindex
echo "Invoking test_tantan"
./test_tantan
echo "Invoking test_translate"
./test_translate
echo "Invoking test_util"
./test_util
echo "Invoking test_scorematrixserialization"
./test_scorematrixserialization
echo "Invoking test_bestalphabet"
./test_bestalphabet
echo "Invoking test_dbreader"
./test_dbreader
echo "Invoking test_dbreaderindexserialization"
./test_dbreaderindexserialization
echo "Invoking test_dbreaderzstd"
./test_dbreaderzstd

# Takes a very long time to complete
#echo "Invoke test_alignmentperformance"
#./test_alignmentperformance
