#!/bin/sh

set -e

# The input file to convert
INFILE=./samples/sample-ascii.txt.gz

# The output file of the conversion
OUTFILE=test-ascii.txt

# The reference file to compare the output against
CMPFILE=./expected/out-ascii.txt

#
# Create temporary directory for test
# output if AUTOPKGTEST_TMP is undefined.
# Debian GNU/Linux defines AUTOPKGTEST_TMP.
#
if [ "x${AUTOPKGTEST_TMP}" = "x" ] ; then
   TEST_TMP=$(mktemp -d)
   trap "\rm -rf ${AUTOPKGTEST_TMP}" 0 INT QUIT ABRT PIPE TERM
else
   TEST_TMP=${AUTOPKGTEST_TMP}
fi

#
# Point to the source directory for test.
#
if [ "x${srcdir}" = "x" ] ; then
   srcdir=.
fi

#
# Point to binary executable; utfcheck_bindir
# should be defined for "make installcheck".
# Otherwise, leave undefined for "make check".
#
if [ "x${utfcheck_bindir}" = "x" ] ; then
   utfcheck_bindir=../src
fi

gunzip < ${srcdir}/${INFILE} | \
   ${utfcheck_bindir}/utfcheck > ${TEST_TMP}/${OUTFILE}

diff ${srcdir}/${CMPFILE} ${TEST_TMP}/${OUTFILE} || \
	(echo "test-ascii FAILED; output in ${TEST_TMP}/${OUTFILE}" ; exit 1)

#
# If AUTOPKGTEST_TMP was defined, don't remove it;
# a Debian calling process will take care of that.
#
if [ "x${AUTOPKGTEST_TMP}" = "x" ] ; then
   \rm -rf ${TEST_TMP}
fi

