|
|
tests.sh - sfeed_tests - sfeed tests and RSS and Atom files |
|
|
 |
git clone git://git.codemadness.org/sfeed_tests (git://git.codemadness.org) |
|
|
 |
Log |
|
|
 |
Files |
|
|
 |
Refs |
|
|
 |
README |
|
|
 |
LICENSE |
|
|
|
--- |
|
|
|
tests.sh (11329B) |
|
|
|
--- |
|
|
|
1 #!/bin/sh |
|
|
|
2 # script for running tests/coverage/etc. Tuned for my system. |
|
|
|
3 |
|
|
|
4 #sfeed="bins/sfeed_gcc_O2_1.0" |
|
|
|
5 |
|
|
|
6 # installed version |
|
|
|
7 #sfeed="sfeed" |
|
|
|
8 |
|
|
|
9 # dev version |
|
|
|
10 sfeed="$HOME/p/sfeed/sfeed" |
|
|
|
11 |
|
|
|
12 # dev version (profiled coverage). |
|
|
|
13 #sfeed="$HOME/p/sfeed/sfeed" |
|
|
|
14 |
|
|
|
15 #program1="bins/sfeed_gcc_O2_0.9.10" |
|
|
|
16 #program1="bins/sfeed_gcc_O2_1.0" |
|
|
|
17 program1="bins/sfeed_gcc_O2_2.0" |
|
|
|
18 #program1="sfeed" |
|
|
|
19 program2="$HOME/p/sfeed/sfeed" |
|
|
|
20 |
|
|
|
21 # force non-builtin printf, requires support for non-POSIX \x. |
|
|
|
22 alias printf='/bin/printf' |
|
|
|
23 |
|
|
|
24 # fixup: expand to same amount of fields, if fields are added (TABS). |
|
|
|
25 # this is useful if the format changes and fields are added. |
|
|
|
26 fixup() { |
|
|
|
27 awk ' |
|
|
|
28 BEGIN { OFS = FS = "\t"; } |
|
|
|
29 { |
|
|
|
30 for (i = 1; i <= 8; i++) { |
|
|
|
31 if (i > 1) |
|
|
|
32 printf("\t"); |
|
|
|
33 printf("%s", $i); |
|
|
|
34 } |
|
|
|
35 printf("\n"); |
|
|
|
36 }' |
|
|
|
37 } |
|
|
|
38 |
|
|
|
39 record_sfeed() { |
|
|
|
40 $sfeed < "$1" | fixup > "$2" |
|
|
|
41 } |
|
|
|
42 |
|
|
|
43 # run all tests, record and store all results as expected output. |
|
|
|
44 record() { |
|
|
|
45 count=0 |
|
|
|
46 for t in input/*/; do |
|
|
|
47 for d in "$t"*/; do |
|
|
|
48 for f in "$d"*; do |
|
|
|
49 test -f "$f" || continue |
|
|
|
50 |
|
|
|
51 dest="expected/${f#input/}" |
|
|
|
52 mkdir -p "$(dirname "$dest")" |
|
|
|
53 record_sfeed "$f" "$dest" |
|
|
|
54 count=$((count+1)) |
|
|
|
55 done |
|
|
|
56 done |
|
|
|
57 done |
|
|
|
58 echo "$count results recorded." |
|
|
|
59 } |
|
|
|
60 |
|
|
|
61 # show all results. |
|
|
|
62 show() { |
|
|
|
63 for t in input/*/; do |
|
|
|
64 for d in "$t"*/; do |
|
|
|
65 for f in "$d"*.xml; do |
|
|
|
66 test -f "$f" || continue |
|
|
|
67 dest="expected/${f#input/}" |
|
|
|
68 test -f "$dest" || continue |
|
|
|
69 |
|
|
|
70 $sfeed < "$f" | fixup > /tmp/t |
|
|
|
71 |
|
|
|
72 echo "Input XML:" |
|
|
|
73 cat "$f" |
|
|
|
74 echo "" |
|
|
|
75 echo "Expected ($dest):" |
|
|
|
76 cat "$dest" |
|
|
|
77 echo "" |
|
|
|
78 echo "Result:" |
|
|
|
79 cat /tmp/t |
|
|
|
80 echo "" |
|
|
|
81 echo "Diff:" |
|
|
|
82 diff -u "$dest" /tmp/t |
|
|
|
83 done |
|
|
|
84 done |
|
|
|
85 done |
|
|
|
86 } |
|
|
|
87 |
|
|
|
88 # run and show only if the expected result differs. |
|
|
|
89 run() { |
|
|
|
90 status=0 |
|
|
|
91 count=0 |
|
|
|
92 for t in input/*/; do |
|
|
|
93 for d in "$t"*/; do |
|
|
|
94 for f in "$d"*.xml; do |
|
|
|
95 test -f "$f" || continue |
|
|
|
96 dest="expected/${f#input/}" |
|
|
|
97 test -f "$dest" || continue |
|
|
|
98 |
|
|
|
99 $sfeed < "$f" | fixup > /tmp/t |
|
|
|
100 if ! cmp -s "$dest" /tmp/t; then |
|
|
|
101 status=1 |
|
|
|
102 echo "" |
|
|
|
103 echo "$f differs" |
|
|
|
104 echo "Input XML:" |
|
|
|
105 cat "$f" |
|
|
|
106 echo "" |
|
|
|
107 echo "Expected ($dest):" |
|
|
|
108 cat "$dest" |
|
|
|
109 echo "" |
|
|
|
110 echo "Result:" |
|
|
|
111 cat /tmp/t |
|
|
|
112 echo "" |
|
|
|
113 echo "Diff:" |
|
|
|
114 diff -u "$dest" /tmp/t |
|
|
|
115 fi |
|
|
|
116 count=$((count+1)) |
|
|
|
117 done |
|
|
|
118 done |
|
|
|
119 done |
|
|
|
120 echo "$count results run." |
|
|
|
121 exit $status |
|
|
|
122 } |
|
|
|
123 |
|
|
|
124 # run and compare with program versions (don't compare to recorded expected results). |
|
|
|
125 run2() { |
|
|
|
126 status=0 |
|
|
|
127 count=0 |
|
|
|
128 baseurl="" |
|
|
|
129 # baseurl="incorrect" |
|
|
|
130 # baseurl="https://codemadness.org/" # TEST baseurl |
|
|
|
131 |
|
|
|
132 # for param in "" "http://a/" "https://a/" "gopher://a/" "http://a:8080/path/"; do |
|
|
|
133 for t in input/*/; do |
|
|
|
134 for d in "$t"*/; do |
|
|
|
135 for f in "$d"*.xml; do |
|
|
|
136 test -f "$f" || continue |
|
|
|
137 |
|
|
|
138 $program1 $baseurl < "$f" | fixup > /tmp/t1 |
|
|
|
139 $program2 $baseurl < "$f" | fixup > /tmp/t2 |
|
|
|
140 if ! cmp -s /tmp/t1 /tmp/t2; then |
|
|
|
141 status=1 |
|
|
|
142 echo "" |
|
|
|
143 echo "$f differs" |
|
|
|
144 echo "Input XML:" |
|
|
|
145 cat "$f" |
|
|
|
146 echo "" |
|
|
|
147 echo "Expected:" |
|
|
|
148 cat /tmp/t1 |
|
|
|
149 echo "" |
|
|
|
150 echo "Result:" |
|
|
|
151 cat /tmp/t2 |
|
|
|
152 echo "" |
|
|
|
153 echo "Diff:" |
|
|
|
154 diff -u /tmp/t1 /tmp/t2 |
|
|
|
155 fi |
|
|
|
156 count=$((count+1)) |
|
|
|
157 done |
|
|
|
158 done |
|
|
|
159 done |
|
|
|
160 echo "$count results run." |
|
|
|
161 exit $status |
|
|
|
162 } |
|
|
|
163 |
|
|
|
164 # run program on input for code coverage purposes. |
|
|
|
165 # contains some specific tests (passing parameters, etc). |
|
|
|
166 coverage() { |
|
|
|
167 testprogram="$HOME/p/sfeed/sfeed" |
|
|
|
168 |
|
|
|
169 for baseurl in "" "https://codemadness.org/"; do |
|
|
|
170 for t in input/*/; do |
|
|
|
171 for d in "$t"*/; do |
|
|
|
172 for f in "$d"*.xml; do |
|
|
|
173 test -f "$f" || continue |
|
|
|
174 |
|
|
|
175 $testprogram $baseurl < "$f" >/dev/null 2>/dev/null |
|
|
|
176 done |
|
|
|
177 done |
|
|
|
178 done |
|
|
|
179 done |
|
|
|
180 |
|
|
|
181 # some very specific-tests. |
|
|
|
182 echo "" | $testprogram "" >/dev/null 2>/dev/null |
|
|
|
183 echo "" | $testprogram "http://127.0.0.1:-1" >/dev/null 2>/dev/null |
|
|
|
184 echo "" | $testprogram "http://127.0.0.1:65536" >/dev/null 2>/dev/null |
|
|
|
185 echo "" | $testprogram "http://127.0.0.1:12345678" >/dev/null 2>/dev/null |
|
|
|
186 echo "" | $testprogram "http://[" >/dev/null 2>/dev/null |
|
|
|
187 echo "" | $testprogram "http://[]" >/dev/null 2>/dev/null |
|
|
|
188 echo "" | $testprogram "codemadness.org" >/dev/null 2>/dev/null |
|
|
|
189 echo "" | $testprogram "https://codemadness.org" >/dev/null 2>/dev/null |
|
|
|
190 echo "" | $testprogram "ftp://user:password@[2001:db8::7]:2121/rfc/rfc1808.txt?q=bla#abc@def" >/dev/null 2>/dev/null |
|
|
|
191 echo "" | $testprogram "mailto:tests@codemadness.org" >/dev/null 2>/dev/null |
|
|
|
192 |
|
|
|
193 # too long URI fields. |
|
|
|
194 nottoolong="0123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790" |
|
|
|
195 long="0123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456789" |
|
|
|
196 echo "" | $testprogram "http://host/$long" >/dev/null 2>/dev/null |
|
|
|
197 echo "" | $testprogram "http://host/?$long" >/dev/null 2>/dev/null |
|
|
|
198 echo "" | $testprogram "http://host/#$long" >/dev/null 2>/dev/null |
|
|
|
199 echo "" | $testprogram "mailto012345679012345679012345679012345679012345679:test" >/dev/null 2>/dev/null |
|
|
|
200 echo "" | $testprogram "http://012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679:pw@codemadness.org" >/dev/null 2>/dev/null |
|
|
|
201 echo "" | $testprogram "http://[012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679012345679]" >/dev/null 2>/dev/null |
|
|
|
202 |
|
|
|
203 # truncation of path: prints original string. |
|
|
|
204 echo "<item><link>$nottoolong</link></item>" | $testprogram "http://host/a" >/dev/null 2>/dev/null |
|
|
|
205 echo "<item><link>$long</link></item>" | $testprogram "http://host/a" >/dev/null 2>/dev/null |
|
|
|
206 echo "<item><link>$nottoolong</link></item>" | $testprogram "http://host/$nottoolong/ab" >/dev/null 2>/dev/null |
|
|
|
207 echo "<item><link>$nottoolong</link></item>" | $testprogram "http://host/$nottoolong" >/dev/null 2>/dev/null |
|
|
|
208 echo "<item><link>$nottoolong</link></item>" | $testprogram "http://host/$long" >/dev/null 2>/dev/null |
|
|
|
209 |
|
|
|
210 cd "$HOME/p/sfeed" |
|
|
|
211 # test empty relative path with absolute URI (sfeed doesn't process this, but sfeed_web does). |
|
|
|
212 printf '<link type="application/xml" href="" >' | ./sfeed_web 'http://codemadness.org' > /dev/null |
|
|
|
213 # HTML |
|
|
|
214 ./sfeed_html nonexistant 2> /dev/null >/dev/null |
|
|
|
215 printf '0\tsome title<&"%s>\n' "'" | ./sfeed_html > /dev/null |
|
|
|
216 printf '0\ta\n' | ./sfeed_html > /dev/null |
|
|
|
217 printf '0\ta\n' | ./sfeed_html /dev/stdin > /dev/null |
|
|
|
218 printf '20000000000\ta\n' | ./sfeed_html 2> /dev/null >/dev/null # new |
|
|
|
219 printf '0\ta\thttp://codemadness.org\n' | ./sfeed_html 2> /dev/null >/dev/null |
|
|
|
220 printf '\ta\thttp://codemadness.org\n' | ./sfeed_html 2> /dev/null >/dev/null |
|
|
|
221 printf '20000000000\ta\thttp://codemadness.org\n' | ./sfeed_html 2> /dev/null >/dev/null |
|
|
|
222 printf '20000000000\ta\thttp://codemadness.org\n' | ./sfeed_html /dev/stdin 2> /dev/null >/dev/null |
|
|
|
223 |
|
|
|
224 # plain |
|
|
|
225 ./sfeed_plain nonexistant 2> /dev/null |
|
|
|
226 # invalid timestamp and line with less fields. |
|
|
|
227 printf 'invalid\ta\n' | ./sfeed_plain > /dev/null |
|
|
|
228 printf 'invalid\ta\n' | ./sfeed_plain /dev/stdin > /dev/null |
|
|
|
229 printf '20000000000\ta\n' | ./sfeed_plain > /dev/null # marked as new. |
|
|
|
230 # sfeed_plain: test padding |
|
|
|
231 printf '0\t' | ./sfeed_plain > /dev/null |
|
|
|
232 printf '0\t\x07' | ./sfeed_plain > /dev/null |
|
|
|
233 printf '0\t\x09' | ./sfeed_plain > /dev/null |
|
|
|
234 printf '0\t\xc3\xc3\xc3' | ./sfeed_plain > /dev/null |
|
|
|
235 printf '0\t\xef\xbf\xba' | ./sfeed_plain > /dev/null |
|
|
|
236 printf '0\t\xef\xbf\xba\xef\xbf\xba' | ./sfeed_plain > /dev/null |
|
|
|
237 |
|
|
|
238 printf '0\t0000000000111111111122222222223333333333444444444455555555556666666666\xef\xbf\xba' | ./sfeed_plain > /dev/null |
|
|
|
239 printf '0\t000000000011111111112222222222333333333344444444445555555555666666666\xef\xbf\xba' | ./sfeed_plain > /dev/null |
|
|
|
240 printf '0\t0000000000111111111122222222223333333333444444444455555555556666666666\xef\xbf\xbe' | ./sfeed_plain > /dev/null |
|
|
|
241 printf '0\t000000000011111111112222222222333333333344444444445555555555666666666\xef\xbf\xbe' | ./sfeed_plain > /dev/null |
|
|
|
242 printf '0\t0000000000111111111122222222223333333333444444444455555555556666666666\xef\xbc\x84' | ./sfeed_plain > /dev/null |
|
|
|
243 printf '0\t000000000011111111112222222222333333333344444444445555555555666666666\xef\xbc\x84' | ./sfeed_plain > /dev/null |
|
|
|
244 printf '0\t0000000000111111111122222222223333333333444444444455555555556666666666\xc3' | ./sfeed_plain > /dev/null |
|
|
|
245 printf '0\t000000000011111111112222222222333333333344444444445555555555666666666\xc3' | ./sfeed_plain > /dev/null |
|
|
|
246 printf '0\t000000000011111111112222222222333333333344444444445555555555666666666\xc3\xc3' | ./sfeed_plain > /dev/null |
|
|
|
247 |
|
|
|
248 # test overflow checks (compiled with MAX_MEM=409600). |
|
|
|
249 (echo "<entry><content>" |
|
|
|
250 i=0 |
|
|
|
251 while :; do |
|
|
|
252 test $i = 52428 && break |
|
|
|
253 echo "AAAAAAAAAA'" |
|
|
|
254 i=$((i+1)) |
|
|
|
255 done |
|
|
|
256 echo "</content></entry>") | $testprogram >/dev/null 2>/dev/null |
|
|
|
257 |
|
|
|
258 # generate gcov coverage files. |
|
|
|
259 for f in sfeed.c sfeed_html.c sfeed_plain.c util.c xml.c; do |
|
|
|
260 gcov "$f" >/dev/null |
|
|
|
261 done |
|
|
|
262 |
|
|
|
263 # coverage statistics. |
|
|
|
264 for f in sfeed.c util.c xml.c sfeed_plain.c sfeed_html.c; do |
|
|
|
265 awk ' |
|
|
|
266 { |
|
|
|
267 total++; |
|
|
|
268 } |
|
|
|
269 /^ #####:/ { |
|
|
|
270 uncov++; |
|
|
|
271 } |
|
|
|
272 END { |
|
|
|
273 cov = total - uncov; |
|
|
|
274 |
|
|
|
275 printf("%s: %d of %d lines covered, %.2f%%\n", |
|
|
|
276 FILENAME, |
|
|
|
277 cov, total, |
|
|
|
278 ((cov / total) * 100.0)); |
|
|
|
279 } |
|
|
|
280 ' "$f.gcov" |
|
|
|
281 done |
|
|
|
282 } |
|
|
|
283 |
|
|
|
284 case "$1" in |
|
|
|
285 "coverage"|"record"|"run"|"run2"|"show") |
|
|
|
286 $1;; |
|
|
|
287 "") |
|
|
|
288 run;; |
|
|
|
289 *) |
|
|
|
290 echo "$0 <coverage|record|run|run2|show>" >&2 |
|
|
|
291 exit 1;; |
|
|
|
292 esac |
|