#!/bin/bash

. ../../scripts/CONFIG.sh

program=${1:-test_parse}

case `uname` in
  Darwin|AIX|OSF1|HP-UX|CYGWIN*)
    if [ "$HOST_CPU" != "ia64" -a -f ${program}.stabs.out ]; then
      out_file=${program}.stabs.out
    else
      out_file=${program}.out
    fi
    ;;
  *) out_file=${program}.out
esac

if [ $program = test_parse_cpp ]; then
   if g++ --version | head -1 | fgrep 3.4 > /dev/null; then
      out_file=test_parse_cpp.out_3_4
   else
      out_file=${program}.out
   fi
fi

cd ../obj
./$program | tr -d '\r' > t

id=$$
sed -e 's/0x[0-9a-f]*/0xffff/g'\
    -e 's/\"\\\(.*\)\"/\"\"/'\
    -e 's/\(<Address 0xffff out of bounds>\)/\"\"/' t\
    > /tmp/t.id
sed -e 's/0x[0-9a-f]*/0xffff/g'\
    -e 's/\(<Address 0xffff out of bounds>\)/\"\"/' ../tests/$out_file\
    > /tmp/t2.id

echo "Diff for $program"
$diff /tmp/t2.id /tmp/t.id
result=$?

rm -f /tmp/t.id /tmp/t2.id
exit $result
