#!/bin/sh
# autopkgtest check: Run goby in fasta-to-compact mode, first with a java call,
# then through the goby shell wrapper. 
# (C) 2021 Pierre Gruet.
# Author: Pierre Gruet <pgt@debian.org>
set -e

pkg=libgoby-java

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 test-data/ "${AUTOPKGTEST_TMP}"

cd "${AUTOPKGTEST_TMP}/test-data/seq-var-test"

# We launch a command in fasta-to-compact mode without the wrapper.
java -Xmx100m -jar /usr/share/java/goby.jar -m fasta-to-compact -d -o small-synth.compact-reads small-synth.fa | grep "Total logical entries written: 1"

if [ $? -eq 0 ]; then
  echo "Result file correctly outputted by the java invocation"
else
  echo "Failed to generate output"
  exit 1
fi

# Now we delete the output and try to launch a command in fasta-to-compact mode
# by invoking the shell launcher.
rm small-synth.compact-reads
goby 100m fasta-to-compact -d -o small-synth.compact-reads small-synth.fa | grep "Total logical entries written: 1"

if [ $? -eq 0 ]; then
  echo "Result file correctly outputted by the goby call"
else
  echo "Failed to generate output"
  exit 1
fi
