#!/bin/sh
# autopkgtest check: build and run with default test data
# Author: Tatiana Malygina <merlettaia@gmail.com>

set -e

pkg=proftmb

if [ "$ADTTMP" = "" ] ; then
  ADTTMP=$(mktemp -d /tmp/${pkg}-test.XXXXXX)
  trap "rm -rf $ADTTMP" 0 INT QUIT ABRT PIPE TERM
fi

cd $ADTTMP
cp -a /usr/share/doc/${pkg}/examples/* .
find . -type f -name "*.gz" -exec gunzip \{\} \;
for lnk in `find . -type l -name "*.gz"` ; do
    ln -s `basename $(readlink $lnk) .gz` `echo $lnk | sed 's/\.gz$//'`
    rm $lnk
done

echo "Run proftmb..."
# call example from man:
proftmb @/usr/share/${pkg}/options -q example.Q -o result

echo "Checking output files existance..."
#according to man, there should be 3 files:
[ -s result_proftmb_tabular.txt ]
[ -s result_proftmb_pretty.txt ]
[ -s result_dat.txt ]

[ -s example_proftmb_tabular.txt ]
[ -s example_proftmb_pretty.txt ]
[ -s example_dat.txt ]

#compare them with expected example output:
echo "Comparing result with expected example output..."
[ -z $( cmp -s result_proftmb_tabular.txt example_proftmb_tabular.txt ) ]
echo "...files result_proftmb_tabular.txt and example_proftmb_tabular.txt match"

[ -z $( cmp -s result_proftmb_pretty.txt example_proftmb_pretty.txt ) ]
echo "...files result_proftmb_pretty.txt and example_proftmb_pretty.txt match"

[ -z $( cmp -s result_dat.txt example_dat.txt ) ]
echo "...files result_dat.txt and example_dat.txt match"
