#!/bin/bash
set -e

pkg=hyphy-common

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

for D in /usr/share/doc/${pkg}/examples/*; do if [ -d "${D}" ]; then cp  -a ${D}/* "${AUTOPKGTEST_TMP}"; fi; done

cd "${AUTOPKGTEST_TMP}"

gunzip -r *

# Remove tests that need UI
rm -f ReplicateConstraint3.bf F81K81uf_relratio.bf definitions.bf definitions+MLE.bf

# Check why tests are failing
rm -f RelativeRatePBS.bf ParametricBootstrap.bf

# Remove failing tests on 32-bit architectures
if [ $(dpkg-architecture -qDEB_BUILD_ARCH_BITS) = 32 ]
then
	rm -f ExonIntron.bf
fi

# Just for debugging
set -x

for i in *.bf; do
    [ -f "$i" ] || break
    hyphy "$i"
done

# Clean up
rm -f *messages.log* *errors.log*
