Debian Codegraph @

tests/testit.sh

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