#!/bin/bash
set -e

pkg=abpoa

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}"

set -x

# Test as many variants of the program as the test node permits
for SIMDE in avx2 avx sse4.1 ssse3 sse3 generic dispatch
do
	if [ "$SIMDE" = "dispatch" ]
	then BINARY="abpoa"
	elif grep -q "$SIMDE" /proc/cpuinfo || [ "$SIMDE" = "generic" ]
	then BINARY="abpoa.$SIMDE"
	else continue
	fi

	# Tests inspired by the README.md document
	"$BINARY" ./test_data/seq.fa > cons.fa
	"$BINARY" ./test_data/heter.fa > 2cons.fa
	"$BINARY" -r1 ./test_data/seq.fa > out.msa
	"$BINARY" -r2 ./test_data/seq.fa > out_cons.msa
	"$BINARY" -r3 ./test_data/seq.fa > out.gfa
	"$BINARY" -r4 ./test_data/seq.fa > out4.gfa
	cp out.gfa in.gfa
	cp out.msa in.msa
	"$BINARY" -i in.gfa ./test_data/seq.fa -r3 > out.gfa
	"$BINARY" -i in.msa ./test_data/seq.fa -r1 > out.msa
	"$BINARY" ./test_data/seq.fa -g poa.png > cons.fa
	"$BINARY" ./test_data/heter.fa -d2
done
