#!@SH_PROG@
# -*- shell-script -*-
t=${0##*/}; TEST_NAME=${t:5}   # basename $0 with 'test-' stripped off
SH=@SH_PROG@

# Put this trap into a known state to make the test more reproducible.
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=801372
trap '' SIGXFSZ

[ -z "$builddir" ] && export builddir=$PWD

. ${builddir}/check-common.sh
debugged_script="$top_srcdir/test/example/sig.sh"

typeset short_test_name='sig'
if (( ${BASH_VERSINFO[0]} == 4 && ${BASH_VERSINFO[1]} == 1 )) ; then
    RIGHT_FILE="${top_srcdir}/test/data/${TEST_NAME}-41.right"
elif (( ${BASH_VERSINFO[0]} == 4 && ${BASH_VERSINFO[1]} == 3 )) ; then
    short_test_name='sig-43'
    RIGHT_FILE="${top_srcdir}/test/data/${TEST_NAME}-43.right"
elif (( ${BASH_VERSINFO[0]} == 4 && ${BASH_VERSINFO[1]} >= 4 )) ; then
    RIGHT_FILE="${top_srcdir}/test/data/${TEST_NAME}-44.right"
elif (( ${BASH_VERSINFO[0]} == 5 && ${BASH_VERSINFO[0]} >= 0 )) ; then
    RIGHT_FILE="${top_srcdir}/test/data/${TEST_NAME}-50.right"
fi

case $host_os in
    freebsd* | netbsd* )
	exit 77 ;;
    darwin* )
	RIGHT_FILE="${top_srcdir}/test/data/${TEST_NAME}-Darwin.right"
	;;
    * )
esac

# This test has been too much of a pain
exit 77

FILTERED_TEST_FILE="/tmp/${TEST_NAME}-filtered.check"
FILTERED_RIGHT_FILE="/tmp/${TEST_NAME}-filtered.right"

typeset dbg_opts="-L ${top_srcdir} $run_debugger_opts"
typeset cmdfile="${top_srcdir}/test/data/${short_test_name}.cmd"

(cd $srcdir && run_debugger "$debugged_script" "$dbg_opts" "$cmdfile" 2>&1 >$TEST_FILE </dev/null)

@GREP@ -v '^sig.tests: line 12' $RIGHT_FILE>${FILTERED_RIGHT_FILE}
@GREP@ -v '^sig.tests: line 12' $TEST_FILE \
  | @SED@ -e "s:in file \`sig.sh' at line [0-9][0-9]*:in file \`sig.sh' at line 55:" \
  | @SED@ -e "s:in file \`eval.sh' at line [0-9][0-9]*:in file \`eval.sh' at line 55:" \
  | @SED@ -e "s:bashdb_eval_[0-9][0-9]*:bashdb_eval_5040:" \
  | @SED@ -e "s:main(.*) called from file \`bashdb' at line 0:main() called from file \`bashdb' at line 0:" \
  | @GREP@ -v '^sig.tests: line 10:' | \
@GREP@ -v '^SIGPIPE' | \
@GREP@ -v '^SIGSYS' | \
@GREP@ -v '^SIGPROF' >${FILTERED_TEST_FILE}
check_output $FILTERED_TEST_FILE $FILTERED_RIGHT_FILE
rc=$?

((0 != rc)) && exit $rc
rm $FILTERED_RIGHT_FILE
rm $TEST_FILE

# Return code tells testing mechanism whether passed or not.
exit 0
