#!/bin/bash
#  $HeadURL: http://dione.no-ip.org/svn/ade/tags/1.7.6/lib/tests/bin/ADESTDTEST103_option_list-paths.sh $ $LastChangedRevision: 3171 $
set -e
PROGNAME=`basename $0`
SANDPIT=`pwd`
. $(ade-config ade_include_prefix)/adetestsupport.sh

##############################################################################
#
#  LOAD TEST-SPECIFIC CONFIGURATION FILE
#
##############################################################################

[ "X$ADETEST_MODROOT" != X ] || error "'ADETEST_MODROOT' not defined"
[ -r "$ADETEST_MODROOT/tests/in/$PROGNAME" ] || error "can't read $ADETEST_MODROOT/tests/in/$PROGNAME"
. "$ADETEST_MODROOT/tests/in/$PROGNAME" || error "problem sourcing $ADETEST_MODROOT/tests/in/$PROGNAME"
[ "X$PROGRAMS" != X ] || error "'PROGRAMS' not defined"

##############################################################################
#
#  START OF TESTS
#
##############################################################################

echo "checking exit codes with '-p' ..."
for PROGRAM in $PROGRAMS; do
    #  The value of $PROGRAM may contain hyphens, but OPTIONS_$PROGRAM is not 
    #  allowed to or it is not a valid variable name. So 'sed' them out.
    eval OPTIONS=\"\$OPTIONS_`echo $PROGRAM | sed 's/-/_/g'`\"
    debug 4 "calling '$PROGRAM $OPTIONS -p' and checking return code ..."
    $PROGRAM $OPTIONS -p > /dev/null
done

echo "checking exit codes with '--list-paths' ..."
for PROGRAM in $PROGRAMS; do
    #  The value of $PROGRAM may contain hyphens, but OPTIONS_$PROGRAM is not 
    #  allowed to or it is not a valid variable name. So 'sed' them out.
    eval OPTIONS=\"\$OPTIONS_`echo $PROGRAM | sed 's/-/_/g'`\"
    debug 4 "calling '$PROGRAM $OPTIONS -p' and checking return code ..."
    $PROGRAM $OPTIONS --list-paths > /dev/null
done

echo "checking reply format with '-p' ..."
for PROGRAM in $PROGRAMS; do
    #  The value of $PROGRAM may contain hyphens, but OPTIONS_$PROGRAM is not 
    #  allowed to or it is not a valid variable name. So 'sed' them out.
    eval OPTIONS=\"\$OPTIONS_`echo $PROGRAM | sed 's/-/_/g'`\"
    debug 4 "running '$PROGRAM $OPTIONS -p' and checking reply format ..."
    $PROGRAM $OPTIONS -p | sed "/^[-A-Za-z]*: \~\{0,1\}[-,_A-Za-z/\.0-9]*$/d"
done

echo "checking reply format with '--list-paths' ..."
for PROGRAM in $PROGRAMS; do
    #  The value of $PROGRAM may contain hyphens, but OPTIONS_$PROGRAM is not 
    #  allowed to or it is not a valid variable name. So 'sed' them out.
    eval OPTIONS=\"\$OPTIONS_`echo $PROGRAM | sed 's/-/_/g'`\"
    debug 4 "running '$PROGRAM $OPTIONS --list-paths' and checking reply format ..."
    $PROGRAM $OPTIONS --list-paths | sed "/^[-A-Za-z]*: \~\{0,1\}[-,_A-Za-z/\.0-9]*$/d"
done
