#!/bin/bash
set -e

pkg=filtlong

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

echo -e "\e[93m\e[1mTest 1\e[0m"
filtlong --keep_percent 75 test_sort.fastq > temp.fastq
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 2\e[0m"
filtlong --min_length 10 test_sort.fastq > temp.fastq
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 3\e[0m"
filtlong --min_length 1 -a test_reference.fasta test_split.fastq > temp.fastq
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 4\e[0m"
filtlong --min_length 1000 --window_size 10 test_sort.fastq > temp.fastq
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 5\e[0m"
filtlong --min_mean_q 5 test_sort.fastq > temp.fastq
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 6\e[0m"
filtlong --min_window_q 5 test_sort.fastq > temp.fastq
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 7\e[0m"
filtlong --target_bases 10000 test_sort.fastq > temp.fastq
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 8\e[0m"
filtlong -1 test_reference_1.fastq.gz -2 test_reference_2.fastq.gz --split 25 test_split.fastq > temp.fastq
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 9\e[0m"
filtlong -1 test_reference_1.fastq.gz -2 test_reference_2.fastq.gz --target_bases 10000 test_sort.fastq > temp.fastq
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 10\e[0m"
filtlong -1 test_reference_1.fastq.gz -2 test_reference_2.fastq.gz --trim test_trim.fastq > temp.fastq
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 11\e[0m"
filtlong -a test_reference.fasta --split 250 test_split.fastq > temp.fastq
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 12\e[0m"
filtlong -a test_reference.fasta --target_bases 1 test_sort.fastq > temp.fastq
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 13\e[0m"
filtlong -a test_reference.fasta --target_bases 10000 test_sort.fastq > temp.fastq
echo -e "\e[92m\e[1mPassed\e[0m"
echo

echo -e "\e[93m\e[1mTest 14\e[0m"
filtlong -a test_reference.fasta --trim test_trim.fastq > temp.fastq
echo -e "\e[92m\e[1mPassed\e[0m"
echo