#!/bin/bash
set -e

pkg="fastqc"

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

find . -name "*.gz" -exec gunzip \{\} \;

for sample in example.fastq toy.sam toy.bam ; do
    /usr/bin/fastqc "$sample"
    if [ "$sample" = "example.fastq" ] ; then
        result=example_fastqc
    else
        result=toy_fastqc
    fi
    unzip -q "$result".zip
    if grep -q FAIL "$result"/summary.txt ; then
        cat <<EOT
There were some failures logged in summary of
    fastqc "$sample"
Please investigate!
EOT
        grep FAIL "$result"/summary.txt
    else
        echo "All passing in:  fastqc "$sample" "
    fi
    rm -rf "$result"*
    echo ""
done

echo "PASS"
