#!/bin/bash
set -e

CUR_DIR=`pwd`
export LC_ALL=C.UTF-8
if [ "${AUTOPKGTEST_TMP}" = "" ] ; then
  AUTOPKGTEST_TMP=$(mktemp -d /tmp/${pkg}-test.XXXXXX)
  # Double quote below to expand the temporary directory variable now versus
  # later is on purpose.
  # shellcheck disable=SC2064
  trap "rm -rf ${AUTOPKGTEST_TMP}" 0 INT QUIT ABRT PIPE TERM
fi

cp -a ${CUR_DIR}/sucpp/test.* "${AUTOPKGTEST_TMP}"
cp -a ${CUR_DIR}/sucpp/test_api.cpp "${AUTOPKGTEST_TMP}"
cp -a ${CUR_DIR}/unifrac/tests "${AUTOPKGTEST_TMP}"

cd "${AUTOPKGTEST_TMP}"

# Check functionalities, and run unit tests
echo "Test 1 -- ssu test"
ssu -i test.biom -t test.tre -m unweighted -o test.out
[ -s test.out ] || exit 1
cat test.out
rm -f test.out
echo "======= PASS ==========="
echo

echo "Test 2 -- faithpd test"
faithpd -i tests/data/crawford.biom -t tests/data/crawford.tre -o test.out
[ -s test.out ] || exit 1
cat test.out
rm -f test.out
echo "======= PASS ==========="
echo

echo "Test 3 -- API test"
g++ test_api.cpp -o test_api -I/usr/include/sucpp -lssu
./test_api
rm -f ./test_api
echo "====== PASS ==========="
echo

echo "Test 4 -- Unifrac python tests"
for py in $(py3versions -s 2> /dev/null)
do
	$py -m unittest -v
done
echo "====== PASS ==========="
echo
