#!/bin/bash
set -e

pkg=prinseq-lite-examples

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 -v

# prinseq-lite
prinseq-lite --version
prinseq-lite.pl -help || test "$?" = 1
whatis prinseq-lite
whatis prinseq-lite.pl

prinseq-lite -verbose -fastq example1.fastq -graph_data pkgtest1.gd \
	-out_good null -out_bad null
test -s pkgtest1.gd

prinseq-lite -verbose -fastq example1.fastq -graph_data pkgtest2.gd \
	-out_good null -out_bad null -exact_only
test -s pkgtest2.gd

# prinseq-graph
prinseq-graphs --version
prinseq-graphs.pl -help || test "$?" = 1
whatis prinseq-graphs
whatis prinseq-graphs.pl

prinseq-graphs -verbose -i example1.gd -png_all -o pkgtest1
test -s pkgtest1_cd.png
test -s pkgtest1_ce.png
test -s pkgtest1_df.png
test -s pkgtest1_dl.png
test -s pkgtest1_dm.png
test -s pkgtest1_gc.png
test -s pkgtest1_ld.png
test -s pkgtest1_ns.png
test -s pkgtest1_or.png
test -s pkgtest1_qd.png
test -s pkgtest1_qd2.png
test -s pkgtest1_qd3.png
test -s pkgtest1_td3.png
test -s pkgtest1_td5.png
test -s pkgtest1_pm.png
test -s pkgtest1_pv.png

prinseq-graphs.pl -verbose -i example1.gd -html_all -o pkgtest1
test -s pkgtest1.html

# prinseq-graphs-noPCA
prinseq-graphs-noPCA --version
prinseq-graphs-noPCA.pl -help || test "$?" = 1
whatis prinseq-graphs-noPCA
whatis prinseq-graphs-noPCA.pl

prinseq-graphs-noPCA -verbose -i example1.gd -png_all -o pkgtest2
test -s pkgtest2_cd.png
test -s pkgtest2_ce.png
test -s pkgtest2_df.png
test -s pkgtest2_dl.png
test -s pkgtest2_dm.png
test -s pkgtest2_gc.png
test -s pkgtest2_ld.png
test -s pkgtest2_ns.png
test -s pkgtest2_or.png
test -s pkgtest2_qd.png
test -s pkgtest2_qd2.png
test -s pkgtest2_qd3.png
test -s pkgtest2_td3.png
test -s pkgtest2_td5.png

prinseq-graphs-noPCA.pl -verbose -i example1.gd -html_all -o pkgtest2
test -s pkgtest2.html
