Debian Codegraph @

tests/testit.sh

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