#!/bin/bash

#set -e

TMPDIR=`mktemp -d`

cp tests/map9v3/map9v3.cel ${TMPDIR}/
cp tests/map9v3/map9v3.par ${TMPDIR}/

RET=0

pushd ${TMPDIR}
graywolf -n map9v3 2> stderr.log
RETRUN="$?"
popd

if [ "$RETRUN" != "0" ] ; then
  RET=1
fi

if [ ! -f ${TMPDIR}/map9v3.pl1 ] ; then
  echo "map9v3.pl1 not found after running graywolf"
  RET=1
fi


# Not reliable since different on 64bit vs 32bit architetures
#diff ${TMPDIR}/map9v3.pl1 tests/map9v3/expected/map9v3.pl1
#RETSUB="$?"
#if [ "$RETSUB" != "0" ] ; then
#  RET=1
#fi

if [ ! -f ${TMPDIR}/map9v3.pl2 ] ; then
  echo "map9v3.pl2 not found after running graywolf"
  RET=1
fi

# Not reliable since different on 64bit vs 32bit architetures
#diff ${TMPDIR}/map9v3.pl2 tests/map9v3/expected/map9v3.pl2
#RETSUB="$?"
#if [ "$RETSUB" != "0" ] ; then
#  RET=1
#fi

if [ "$RET" != "0" ] ; then
  echo "stderr from running graywolf -->"
  cat ${TMPDIR}/stderr.log
  echo "<--"
fi

rm -rf ${TMPDIR}
exit ${RET}
