#!/bin/bash
set -e

pkg=paml

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

cd "${AUTOPKGTEST_TMP}"

# These tests take too much time on non-amd64 platforms.
if [ "$(uname -m)" = "x86_64" ]
then
	echo -e "\e[93m\e[1mTest 1\e[0m"
	cd HIVNSsites
	codeml
	cd ..
	echo -e "\e[92m\e[1mPassed\e[0m"
	echo

	echo -e "\e[93m\e[1mTest 2\e[0m"
	cd lysin
	codeml
	echo -e "\e[92m\e[1mPassed\e[0m"
	echo

	echo -e "\e[93m\e[1mTest 3\e[0m"
	codeml codemlYangSwanson2002.ctl
	cd ..
	echo -e "\e[92m\e[1mPassed\e[0m"
	echo
fi

echo -e "\e[93m\e[1mTest 4\e[0m"
cd lysozyme
codeml
echo -e "\e[92m\e[1mPassed\e[0m"
echo

# These tests take too much time on non-amd64 platforms.
if [ "$(uname -m)" = "x86_64" ]
then
	echo -e "\e[93m\e[1mTest 5\e[0m"
	codeml lysozymeSmall.ctl
	echo -e "\e[92m\e[1mPassed\e[0m"
	echo

	echo -e "\e[93m\e[1mTest 6\e[0m"
	codeml lysozymeLarge.ctl
	cd ..
	echo -e "\e[92m\e[1mPassed\e[0m"
	echo

	echo -e "\e[93m\e[1mTest 7\e[0m"
	cd MouseLemurs
	baseml
	cd ..
	echo -e "\e[92m\e[1mPassed\e[0m"
	echo

	echo -e "\e[93m\e[1mTest 8\e[0m"
	cd mtCDNA
	codeml codeml.AAcodon.ctl
	cd ..
	echo -e "\e[92m\e[1mPassed\e[0m"
	echo

	echo -e "\e[93m\e[1mTest 9\e[0m"
	cd mtCDNAape
	codeml
	echo -e "\e[92m\e[1mPassed\e[0m"
	echo

	echo -e "\e[93m\e[1mTest 10\e[0m"
	codeml codeml.HC.ctl
	cd ..
	echo -e "\e[92m\e[1mPassed\e[0m"
	echo
fi
