#!/bin/sh
#
# This is a simple script that tests gengetopt
#
# install as: /usr/lib/debian-test/tests/gengetopt
# or else as: /usr/lib/debian-test/tests/gengetopt/test-1
# In the latter case, /usr/lib/debian-test/tests/gengetopt/ can contain
# other file with test data and/or other scripts named test-2, test-3, etc.
#
# You can run this script with the command
#       sh debian/tests
# After installation, you can run it with the commands
#       /usr/lib/debian-test/tests/gengetopt
# or
#       debian-test -v gengetopt
# see debian-test(1)

. ${DEBIANTEST_LIB:-/usr/lib/debian-test/lib}/functions.sh

if [ -f my-data-file ]; then
    TESTDIR=`pwd`;
else
    TESTDIR=/usr/lib/debian-test/tests/gengetopt;
fi


## we need a scratch directory in which to execute

TMP=/tmp/gengetopt-test.$$
test -e $TMP && rm -rf $TMP
mkdir $TMP
cd $TMP
trap "rm -rf $TMP" EXIT

test1(){
    RESULT=0
    cp /usr/share/doc/gengetopt/examples/* .
    gengetopt -isample1.ggo -Fcmdline1 --long-help -u 
    c++ -o main1 main1.cc cmdline1.c

    if ./main1 --help |grep -q "Another integer option"; then 
	true; 
    else 
	RESULT=1; 
    fi

    return $RESULT
}

test2(){
    RESULT=0
    gengetopt --input=sample2.ggo --func-name=my_cmdline_parser --file-name=cmdline2 --unamed-opts
    gcc -o main2 main2.c cmdline2.c

    if ./main2 -h |grep -q "long double option"; then 
	true; 
    else 
	RESULT=1; 
    fi

    return $RESULT
}

runtest "C++ test case" test1

runtest "C test case" test2

