#!/bin/bash
t=${0##*/}; TEST_NAME=${t:5}   # basename $0 with 'test-' stripped off

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

. ${builddir}/check-common.sh

debugged_script="$top_srcdir/test/example/dbg-test2.sh"

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

# Different OS's handle ARGV differently, and "info args" may come out
# differently depending on that.
cat ${TEST_FILE} | /bin/sed -e "s:1 = .*/dbg-test2.sh:1 = ./example/dbg-test2.sh:" \
| /bin/sed -e 's:record the command history is .*:record the command history is: ' \
| /bin/sed -e 's:step-:step+:' \
| /bin/grep -v '^set dollar0' > ${TEST_FILTERED_FILE}

if (( BASH_VERSINFO[0] > 4 || \
    (BASH_VERSINFO[0] == 4 && BASH_VERSINFO[1] >= 1) )) ; then 
    RIGHT_FILE="${top_srcdir}/test/data/${TEST_NAME}-output-41.right"
fi

check_output $TEST_FILTERED_FILE $RIGHT_FILE
rc=$?

((0 != rc)) && exit $rc
rm -f $TEST_FILE

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