#!/bin/bash
set -e

pkg=blasr

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

cp -a /usr/share/doc/${pkg}/examples/* "${AUTOPKGTEST_TMP}"

cd "${AUTOPKGTEST_TMP}"

blasr query.fasta ref.fa --sam --out alignment.sam
blasr query.fasta ref.fa --minMatch 1 --maxMatch 10 > output
if [ $(dpkg-architecture -qDEB_BUILD_ARCH) = "amd64" ]
then
	echo "8db2f4d5737a90d087da90a6779c8d7b  output" >> checksums
	sed 's/\(PN:BLASR.*VN:\).*5.3.5\(.*\+CL:blasr\)/\1VERSION\2/' alignment.sam > alignment.sam.check

	# Cat orig file for future ref/regressions
	echo "alignment.sam"
	cat alignment.sam

	# Cat expected file for future ref/regressions
	echo "alignment.sam.check:"
	cat alignment.sam.check

	echo "4ff931c75012f8c2e02c75120351e217  alignment.sam.check" >> checksums
	md5sum --check checksums
	echo "Expected output and generated output are same: PASS Test"
else
	[ -s "output" ] && [ -s "alignment.sam" ] || exit 1
	echo "PASS Test"
fi
