#!/bin/bash
set -e

pkg="phyml"

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 /usr/share/doc/${pkg}/examples/* "${AUTOPKGTEST_TMP}"

cd "${AUTOPKGTEST_TMP}"

gunzip -r *

export OMPI_MCA_plm_rsh_agent=/bin/false
export OMPI_MCA_rmaps_base_oversubscribe=1

set -x
export PHYMLCPUS=1
echo "DNA interleaved sequence file, default parameters single processor:"
/usr/bin/phyml -i nucleic

echo "AA interleaved sequence file, default parameters single processor:"
/usr/bin/phyml -i proteic -d aa

echo "AA sequential sequence file, with customization single processor:"
/usr/bin/phyml -i example.nex -d nt -c 4 -a e

export PHYMLCPUS=2
echo "DNA interleaved sequence file, default parameters using $PHYMLCPUS processors:"
/usr/bin/phyml -i nucleic

echo "AA interleaved sequence file, default parameters using $PHYMLCPUS processors:"
/usr/bin/phyml -i proteic -d aa

echo "AA sequential sequence file, with customization using $PHYMLCPUS processors:"
/usr/bin/phyml -i example.nex -d nt -c 4 -a e

echo "PASS"
