#!/bin/sh -e

pkg=bamtools

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

cd $AUTOPKGTEST_TMP

cp -a /usr/share/doc/${pkg}/sam_spec_example.bam .
cp -a /usr/share/doc/${pkg}/filter_script .
gunzip -r *

bamtools convert -format fastq -in sam_spec_example.bam -out test.fastq

bamtools convert -format json -in sam_spec_example.bam -out test.json

bamtools count -in sam_spec_example.bam

bamtools coverage -in sam_spec_example.bam -out out

# This test fails on ppc64el for whatever reason and is for the moment (see bug #933505)
ARCH=$(dpkg --print-architecture)
if [ "$ARCH" != "ppc64el" -a "$ARCH" != "arm64" -a "$ARCH" != "armhf" -a "$ARCH" != "s390x"  ] ; then
   bamtools filter -script filter_script -in sam_spec_example.bam -out out.bam
else
   if [ "$ARCH" = "ppc64el" ] ; then
      echo "The following test is known to fail on ppc64el architecture (see bug #933505)"
   else
      echo "The following test is known to time out on $ARCH architecture (see bug #953939)"
   fi
   echo "bamtools filter -script filter_script -in sam_spec_example.bam -out out.bam"
fi

bamtools header -in sam_spec_example.bam

bamtools index -in sam_spec_example.bam

bamtools random -n 100 -in sam_spec_example.bam -out out.bam

bamtools revert -in sam_spec_example.bam -out out.bam

bamtools sort -in sam_spec_example.bam -out out.bam

bamtools split -mapped -in sam_spec_example.bam

bamtools stats -in sam_spec_example.bam
