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