1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
#!/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
|