• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2
3run() {
4    prog=$1; shift
5    name=$1; shift
6    answer=$1; shift
7
8    echo Running test $name.
9
10    result=`HOME=$builddir $builddir/$prog $*`
11    if [ "$answer" != "$result" ]; then
12	echo "Test \"$prog $*\" failed with: \"$result\" != \"$answer\" "
13	exit 2
14    fi
15}
16
17run_diff() {
18    prog=$1; shift
19    name=$1; shift
20    in_file=$1; shift
21    answer_file=$1; shift
22
23    out=$builddir/tmp.out
24    diff_file=$builddir/tmp.diff
25
26    echo Running test $name.
27
28    $builddir/$prog $in_file > $out
29    ret=$?
30    diff $out $answer_file > $diff_file
31    diff_ret=$?
32
33    if [ "$diff_ret" != "0" ]; then
34       echo "Test \"$name\" failed output is in $out, diff is:"
35       cat $diff_file
36       exit 2
37    fi
38    rm $out $diff_file
39}
40
41builddir=`pwd`
42srcdir=$builddir
43cd ${srcdir}
44test1=${builddir}/test1
45echo "Running tests in `pwd`"
46
47#make -q testcases
48
49run test1 "test1 - 1" "arg1: 1 arg2: (none)" --arg1
50run test1 "test1 - 2" "arg1: 0 arg2: foo" --arg2 foo
51run test1 "test1 - 3" "arg1: 1 arg2: something" --arg1 --arg2 something
52run test1 "test1 - 4" "arg1: 0 arg2: another" --simple another
53run test1 "test1 - 5" "arg1: 1 arg2: alias" --two
54run test1 "test1 - 6" "arg1: 1 arg2: (none) rest: --arg2" --arg1 -- --arg2
55run test1 "test1 - 7" "arg1: 0 arg2: abcd rest: --arg1" --simple abcd -- --arg1
56run test1 "test1 - 8" "arg1: 1 arg2: (none) rest: --arg2" --arg1 --takerest --arg2
57run test1 "test1 - 9" "arg1: 0 arg2: foo" -2 foo
58run test1 "test1 - 10" "arg1: 0 arg2: (none) arg3: 50" -3 50
59run test1 "test1 - 11" "arg1: 0 arg2: bar" -T bar
60run test1 "test1 - 12" "arg1: 1 arg2: (none)" -O
61run test1 "test1 - 13" "arg1: 1 arg2: foo" -OT foo
62run test1 "test1 - 14" "arg1: 0 arg2: (none) inc: 1" --inc
63run test1 "test1 - 15" "arg1: 0 arg2: foo inc: 1" -I --arg2 foo
64POSIX_ME_HARDER=1 ; export POSIX_ME_HARDER
65run test1 "test1 - 16" "arg1: 1 arg2: (none) rest: foo --arg2 something" --arg1 foo --arg2 something
66unset POSIX_ME_HARDER
67POSIXLY_CORRECT=1 ; export POSIXLY_CORRECT
68run test1 "test1 - 17" "arg1: 1 arg2: (none) rest: foo --arg2 something" --arg1 foo --arg2 something
69unset POSIXLY_CORRECT
70run test1 "test1 - 18" "callback: c sampledata bar arg1: 1 arg2: (none)" --arg1 --cb bar
71run test1 "test1 - 19" "" --echo-args
72run test1 "test1 - 20" "--arg1" --echo-args --arg1
73run test1 "test1 - 21" "--arg2 something" -T something -e
74run test1 "test1 - 22" "--arg2 something more args" -T something -a more args
75run test1 "test1 - 23" "--echo-args -a" --echo-args -e -a
76run test1 "test1 - 24" "arg1: 0 arg2: (none) short: 1" -onedash
77run test1 "test1 - 25" "arg1: 0 arg2: (none) short: 1" --onedash
78run test1 "test1 - 26" "callback: c arg for cb2 foo arg1: 0 arg2: (none)" --cb2 foo
79run test1 "test1 - 27" "arg1: 0 arg2: (none) rest: -" -
80run test1 "test1 - 28" "arg1: 0 arg2: foo rest: -" - -2 foo
81run test1 "test1 - 29" "arg1: 0 arg2: bbbb" --arg2=aaaa -2 bbbb
82run test1 "test1 - 30" "arg1: 0 arg2: 'foo bingo' rest: boggle" --grab bingo boggle
83run test1 "test1 - 31" "arg1: 0 arg2: 'foo bar' rest: boggle" --grabbar boggle
84
85run test1 "test1 - 32" "arg1: 0 arg2: (none) aInt: 123456789" -i 123456789
86run test1 "test1 - 33" "arg1: 0 arg2: (none) aInt: 123456789" --int 123456789
87run test1 "test1 - 34" "arg1: 0 arg2: (none) aShort: 12345" -s 12345
88run test1 "test1 - 35" "arg1: 0 arg2: (none) aShort: 12345" --short 12345
89run test1 "test1 - 36" "arg1: 0 arg2: (none) aLong: 1123456789" -l 1123456789
90run test1 "test1 - 37" "arg1: 0 arg2: (none) aLong: 1123456789" --long 1123456789
91run test1 "test1 - 38" "arg1: 0 arg2: (none) aLongLong: 1111123456789" -L 1111123456789
92run test1 "test1 - 39" "arg1: 0 arg2: (none) aLongLong: 1111123456789" --longlong 1111123456789
93
94run test1 "test1 - 40" "arg1: 0 arg2: (none) aFloat: 10.1" -f 10.1
95run test1 "test1 - 41" "arg1: 0 arg2: (none) aFloat: 10.1" --float 10.1
96run test1 "test1 - 42" "arg1: 0 arg2: (none) aDouble: 10.1" -d 10.1
97run test1 "test1 - 43" "arg1: 0 arg2: (none) aDouble: 10.1" --double 10.1
98
99run test1 "test1 - 44" "arg1: 0 arg2: (none) oStr: (none)" --optional
100run test1 "test1 - 45" "arg1: 0 arg2: (none) oStr: yadda" --optional=yadda
101run test1 "test1 - 46" "arg1: 0 arg2: (none) oStr: yadda" --optional yadda
102run test1 "test1 - 47" "arg1: 0 arg2: (none) oStr: ping rest: pong" --optional=ping pong
103run test1 "test1 - 48" "arg1: 0 arg2: (none) oStr: ping rest: pong" --optional ping pong
104run test1 "test1 - 49" "arg1: 0 arg2: (none) aArgv: A B rest: C" --argv A --argv B C
105
106run test1 "test1 - 50" "arg1: 0 arg2: foo=bar" -2foo=bar
107run test1 "test1 - 51" "arg1: 0 arg2: foo=bar" -2=foo=bar
108
109run test1 "test1 - 52" "arg1: 0 arg2: (none) aFlag: 0xfeed" --bitxor
110run test1 "test1 - 53" "arg1: 0 arg2: (none) aFlag: 0xffff" --bitset
111run test1 "test1 - 54" "arg1: 0 arg2: (none) aFlag: 0x28c" --bitclr
112run test1 "test1 - 55" "arg1: 0 arg2: (none) aFlag: 0x8888" --nobitset
113run test1 "test1 - 56" "arg1: 0 arg2: (none) aFlag: 0xface" --nobitclr
114
115run test1 "test1 - 57" "arg1: 0 arg2: (none) aBits: foo,baz" --bits foo,bar,baz,!bar
116
117run test1 "test1 - 58" "\
118Usage: lt-test1 [-I?] [-c|--cb2=STRING] [--arg1] [-2|--arg2=ARG]
119        [-3|--arg3=ANARG] [-onedash] [--optional=STRING] [--val]
120        [-i|--int=INT] [-s|--short=SHORT] [-l|--long=LONG]
121        [-L|--longlong=LONGLONG] [-f|--float=FLOAT] [-d|--double=DOUBLE]
122        [--randint=INT] [--randshort=SHORT] [--randlong=LONG]
123        [--randlonglong=LONGLONG] [--argv=STRING] [--bitset] [--bitclr]
124        [--bitxor] [--nstr=STRING] [--lstr=STRING] [-I|--inc]
125        [-c|--cb=STRING] [--longopt] [-?|--help] [--usage] [--simple=ARG]" --usage
126run test1 "test1 - 59" "\
127Usage: lt-test1 [OPTION...]
128      --arg1                      First argument with a really long
129                                  description. After all, we have to test
130                                  argument help wrapping somehow, right?
131  -2, --arg2=ARG                  Another argument (default: \"(none)\")
132  -3, --arg3=ANARG                A third argument
133      -onedash                    POPT_ARGFLAG_ONEDASH: Option takes a single -
134      --optional[=STRING]         POPT_ARGFLAG_OPTIONAL: Takes an optional
135                                  string argument
136      --val                       POPT_ARG_VAL: 125992 141421
137  -i, --int=INT                   POPT_ARG_INT: 271828 (default: 271828)
138  -s, --short=SHORT               POPT_ARG_SHORT: 4523 (default: 4523)
139  -l, --long=LONG                 POPT_ARG_LONG: 738905609 (default: 738905609)
140  -L, --longlong=LONGLONG         POPT_ARG_LONGLONG: 738905609 (default:
141                                  738905609)
142  -f, --float=FLOAT               POPT_ARG_FLOAT: 3.14159 (default: 3.14159)
143  -d, --double=DOUBLE             POPT_ARG_DOUBLE: 9.8696 (default: 9.8696)
144      --randint=INT               POPT_ARGFLAG_RANDOM: experimental
145      --randshort=SHORT           POPT_ARGFLAG_RANDOM: experimental
146      --randlong=LONG             POPT_ARGFLAG_RANDOM: experimental
147      --randlonglong=LONGLONG     POPT_ARGFLAG_RANDOM: experimental
148      --argv STRING               POPT_ARG_ARGV: append string to argv array
149                                  (can be used multiple times)
150      --[no]bitset                POPT_BIT_SET: |= 0x7777
151      --[no]bitclr                POPT_BIT_CLR: &= ~0xf842
152      --bitxor                    POPT_ARGFLAG_XOR: ^= (0x8ace^0xfeed)
153      --nstr=STRING               POPT_ARG_STRING: (null) (default: null)
154      --lstr=STRING               POPT_ARG_STRING: \"123456789...\" (default:
155                                  \"This tests default strings and exceeds the
156                                  ... limit.
157                                  123456789+123456789+123456789+123456789+123456789+ 123456789+123456789+123456789+123456789+123456789+ 1234567...\")
158
159arg for cb2
160  -c, --cb2=STRING                Test argument callbacks
161  -I, --inc                       An included argument
162
163Callback arguments
164  -c, --cb=STRING                 Test argument callbacks
165      --longopt                   Unused option for help testing
166
167Options implemented via popt alias/exec:
168      --simple=ARG                simple description
169
170Help options:
171  -?, --help                      Show this help message
172      --usage                     Display brief usage message" --help
173
174#run_diff test3 "test3 - 51" test3-data/01.input test3-data/01.answer
175#run_diff test3 "test3 - 52" test3-data/02.input test3-data/02.answer
176#run_diff test3 "test3 - 53" test3-data/03.input test3-data/03.answer
177
178echo ""
179echo "Passed."
180