#!/bin/bash
set -e

pkg=cmaple

export LC_ALL=C.UTF-8
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}"

echo "== cmaple --help reports a version =="
cmaple --help | grep -m1 -oE '[0-9]+(\.[0-9]+)+'

echo "== running cmaple on upstream example (example.maple + tree.nwk) =="
cmaple -aln example.maple -t tree.nwk --overwrite

test -s example.maple.treefile
echo "-- resulting tree (first 200 chars) --"
head -c 200 example.maple.treefile; echo

# sanity check: it should look like a Newick tree
grep -q ';' example.maple.treefile

echo "OK: cmaple produced a tree file"
