#!/bin/bash
set -e

pkg=hyphy-common

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

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 MolecularClockHKY85.bf MolecularClockF81.bf RelativeRatePBS.bf ParametricBootstrap.bf

# Just for debugging
# set -x

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

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