#!/usr/bin/env bash
#
# diff-ignoring-module-line-numbers <test.comp.out.tmp> <test.bad>
#
# Compare the compilation output and .bad files, ignoring line numbers
# in error/warning warning messages arising from module code.
# Also ignore chpl version differences.
#

badfile=$1
tmpfile=$2

badtmp=`mktemp "bad.XXXXXX"`
tmptmp=`mktemp "tmp.XXXXXX"`

command='
  \|CHPL_HOME/modules|s/:[0-9:]*:/:nnnn:/
  s/chpl version [0-9]*.*$/chpl version mmmm/
  s/internal error: \([A-Z][A-Z\-]*\)[0-9][0-9]* chpl version mmmm/internal error: \1nnnn chpl version mmmm/
'

sed -e "$command" $badfile > $badtmp
sed -e "$command" $tmpfile > $tmptmp

diff $badtmp $tmptmp
result=$?
rm $badtmp $tmptmp
exit $result
