|
|
test.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 |
|
|
|
--- |
|
|
|
test.sh (28852B) |
|
|
|
--- |
|
|
|
1 #!/bin/sh |
|
|
|
2 |
|
|
|
3 SFEED_UPDATE="$(command -v sfeed_update)" |
|
|
|
4 [ "$SFEED_UPDATE" != "" ] || exit 1 |
|
|
|
5 |
|
|
|
6 # expect(expect, got, [extra]) |
|
|
|
7 expect() { |
|
|
|
8 if [ "$1" != "$2" ]; then |
|
|
|
9 extra="$3" |
|
|
|
10 [ "$extra" = "" ] || extra="($extra)" |
|
|
|
11 echo "Expected \"$1\", but got \"$2\" $extra" >&2 |
|
|
|
12 |
|
|
|
13 # DEBUG |
|
|
|
14 echo "Last stdout:" |
|
|
|
15 cat "$log_stdout" |
|
|
|
16 echo "" |
|
|
|
17 echo "Last stderr:" |
|
|
|
18 cat "$log_stderr" |
|
|
|
19 exit 1 |
|
|
|
20 fi |
|
|
|
21 } |
|
|
|
22 |
|
|
|
23 init_test() { |
|
|
|
24 rc="$(mktemp /tmp/rc_XXXXXXXX)" |
|
|
|
25 log_stdout="$(mktemp /tmp/stdout_XXXXXXXX)" |
|
|
|
26 log_stderr="$(mktemp /tmp/stderr_XXXXXXXX)" |
|
|
|
27 feedpath="$(mktemp -d /tmp/feedpath_XXXXXXXX)" |
|
|
|
28 } |
|
|
|
29 |
|
|
|
30 # create an rc file with some defaults for testing. |
|
|
|
31 createrc() { |
|
|
|
32 cat <<! |
|
|
|
33 # override default iconv: do not use text decoding. |
|
|
|
34 convertencoding() { |
|
|
|
35 cat |
|
|
|
36 } |
|
|
|
37 # override default cURL: local files are tested. |
|
|
|
38 fetch() { |
|
|
|
39 cat "\${2#file://}" 2>/dev/null |
|
|
|
40 } |
|
|
|
41 ! |
|
|
|
42 # add the rest. |
|
|
|
43 cat |
|
|
|
44 } |
|
|
|
45 |
|
|
|
46 cleanup() { |
|
|
|
47 rm -rf "$feedpath" "$log_stdout" "$log_stderr" "$rc" |
|
|
|
48 } |
|
|
|
49 |
|
|
|
50 # test normal execution, all succesful. |
|
|
|
51 test_normal() { |
|
|
|
52 init_test |
|
|
|
53 |
|
|
|
54 createrc > "$rc" <<! |
|
|
|
55 sfeedpath="$feedpath" |
|
|
|
56 |
|
|
|
57 feeds() { |
|
|
|
58 # feed <name> <feedurl> [basesiteurl] [encoding] |
|
|
|
59 feed "1" "file:///dev/null" |
|
|
|
60 feed "2" "file:///dev/null" |
|
|
|
61 feed "3" "file:///dev/null" |
|
|
|
62 } |
|
|
|
63 ! |
|
|
|
64 |
|
|
|
65 "$SFEED_UPDATE" "$rc" >"$log_stdout" 2>"$log_stderr" |
|
|
|
66 expect "0" "$?" "exit statuscode" |
|
|
|
67 |
|
|
|
68 linecount=$(wc -l < "$log_stdout") |
|
|
|
69 linecount=$((linecount+0)) |
|
|
|
70 expect "3" "$linecount" "all 3 lines should be written to stdout" |
|
|
|
71 |
|
|
|
72 linecount=$(wc -l < "$log_stderr") |
|
|
|
73 linecount=$((linecount+0)) |
|
|
|
74 expect "0" "$linecount" "0 lines should be written to stderr" |
|
|
|
75 |
|
|
|
76 test -d "$feedpath" |
|
|
|
77 expect "0" "$?" "directory should exist: $feedpath" |
|
|
|
78 |
|
|
|
79 for i in 1 2 3; do |
|
|
|
80 f="$feedpath/$i" |
|
|
|
81 test -f "$f" |
|
|
|
82 expect "0" "$?" "file should exist: $f" |
|
|
|
83 done |
|
|
|
84 |
|
|
|
85 cleanup |
|
|
|
86 |
|
|
|
87 echo "test_normal: test OK" >&2 |
|
|
|
88 } |
|
|
|
89 |
|
|
|
90 # test execution where a feed failed. |
|
|
|
91 test_one_fail() { |
|
|
|
92 init_test |
|
|
|
93 |
|
|
|
94 createrc > "$rc" <<! |
|
|
|
95 sfeedpath="$feedpath" |
|
|
|
96 |
|
|
|
97 feeds() { |
|
|
|
98 # feed <name> <feedurl> [basesiteurl] [encoding] |
|
|
|
99 feed "1" "file:///dev/null" |
|
|
|
100 feed "2" "file:///dev/null_fail" |
|
|
|
101 feed "3" "file:///dev/null" |
|
|
|
102 } |
|
|
|
103 ! |
|
|
|
104 |
|
|
|
105 "$SFEED_UPDATE" "$rc" >"$log_stdout" 2> "$log_stderr" |
|
|
|
106 expect "1" "$?" "exit statuscode" |
|
|
|
107 |
|
|
|
108 linecount=$(wc -l < "$log_stdout") |
|
|
|
109 linecount=$((linecount+0)) |
|
|
|
110 expect "2" "$linecount" "2 lines should be written to stdout" |
|
|
|
111 |
|
|
|
112 linecount=$(wc -l < "$log_stderr") |
|
|
|
113 linecount=$((linecount+0)) |
|
|
|
114 expect "1" "$linecount" "1 line should be written to stderr" |
|
|
|
115 |
|
|
|
116 test -d "$feedpath" |
|
|
|
117 expect "0" "$?" "directory should exist: $feedpath" |
|
|
|
118 |
|
|
|
119 for i in 1 2 3; do |
|
|
|
120 f="$feedpath/$i" |
|
|
|
121 test -f "$f" |
|
|
|
122 expect "0" "$?" "file should exist: $f" |
|
|
|
123 done |
|
|
|
124 |
|
|
|
125 cleanup |
|
|
|
126 |
|
|
|
127 echo "test_one_fail: test OK" >&2 |
|
|
|
128 } |
|
|
|
129 |
|
|
|
130 # test SIGTERM |
|
|
|
131 test_sigterm() { |
|
|
|
132 init_test |
|
|
|
133 |
|
|
|
134 tmp=$(mktemp '/tmp/sfeed_sigterm_cleanup_XXXXXXXX') |
|
|
|
135 |
|
|
|
136 createrc > "$rc" <<! |
|
|
|
137 sfeedpath="$feedpath" |
|
|
|
138 |
|
|
|
139 # override |
|
|
|
140 feed() { |
|
|
|
141 _feed "\$@" |
|
|
|
142 sleep 2 |
|
|
|
143 } |
|
|
|
144 |
|
|
|
145 cleanup() { |
|
|
|
146 echo "I'm created on SIGTERM" > "$tmp" |
|
|
|
147 } |
|
|
|
148 |
|
|
|
149 feeds() { |
|
|
|
150 # feed <name> <feedurl> [basesiteurl] [encoding] |
|
|
|
151 feed "1" "file:///dev/null" |
|
|
|
152 feed "2" "file:///dev/null" |
|
|
|
153 feed "3" "file:///dev/null" |
|
|
|
154 } |
|
|
|
155 ! |
|
|
|
156 |
|
|
|
157 "$SFEED_UPDATE" "$rc" >"$log_stdout" 2> "$log_stderr" & |
|
|
|
158 pid="$!" |
|
|
|
159 { |
|
|
|
160 sleep 1 |
|
|
|
161 kill -TERM "$pid" |
|
|
|
162 } & |
|
|
|
163 wait "$pid" |
|
|
|
164 # NOTE: 143 - 15 (SIGTERM) = 128 |
|
|
|
165 expect "143" "$?" "exit statuscode" |
|
|
|
166 |
|
|
|
167 test -d "$feedpath" |
|
|
|
168 expect "0" "$?" "directory should exist: $feedpath" |
|
|
|
169 |
|
|
|
170 # test that cleanup is called on SIGTERM |
|
|
|
171 test -f "$tmp" |
|
|
|
172 expect "0" "$?" "file should exist (test for cleanup function on SIGTERM)" |
|
|
|
173 |
|
|
|
174 rm -f "$tmp" |
|
|
|
175 cleanup |
|
|
|
176 |
|
|
|
177 echo "test_sigterm: test OK" >&2 |
|
|
|
178 } |
|
|
|
179 |
|
|
|
180 test_config_invocation() { |
|
|
|
181 init_test |
|
|
|
182 |
|
|
|
183 rcempty="$(mktemp /tmp/sfeed_emptyrc_XXXXXXXX)" |
|
|
|
184 |
|
|
|
185 "$SFEED_UPDATE" "$rcempty" >/dev/null 2> "$log_stderr" # should say feeds function is not defined. |
|
|
|
186 expect "1" "$?" "exit statuscode" |
|
|
|
187 msg='does not contain a "feeds" function' |
|
|
|
188 fgrep -q "$msg" < "$log_stderr" |
|
|
|
189 expect "0" "$?" "stderr must contain text $msg" |
|
|
|
190 |
|
|
|
191 "$SFEED_UPDATE" /dev/null >/dev/null 2> "$log_stderr" |
|
|
|
192 expect "1" "$?" "exit statuscode" |
|
|
|
193 msg='Configuration file "/dev/null" cannot be read.' |
|
|
|
194 fgrep -q "$msg" < "$log_stderr" |
|
|
|
195 expect "0" "$?" "stderr must contain text $msg" |
|
|
|
196 |
|
|
|
197 "$SFEED_UPDATE" nonexistant >/dev/null 2> "$log_stderr" |
|
|
|
198 expect "1" "$?" "exit statuscode" |
|
|
|
199 msg='Configuration file "nonexistant" cannot be read.' |
|
|
|
200 fgrep -q "$msg" < "$log_stderr" |
|
|
|
201 expect "0" "$?" "stderr must contain text $msg" |
|
|
|
202 |
|
|
|
203 # invalid: must not be a directory. |
|
|
|
204 "$SFEED_UPDATE" `pwd` >/dev/null 2> "$log_stderr" # directory |
|
|
|
205 expect "1" "$?" "exit statuscode" |
|
|
|
206 msg='" cannot be read.' |
|
|
|
207 fgrep -q "$msg" < "$log_stderr" |
|
|
|
208 expect "0" "$?" "stderr must contain text $msg" |
|
|
|
209 |
|
|
|
210 # invalid: must not be a directory. |
|
|
|
211 "$SFEED_UPDATE" /root >/dev/null 2> "$log_stderr" # directory, probably no access |
|
|
|
212 expect "1" "$?" "exit statuscode" |
|
|
|
213 msg='Configuration file "/root" cannot be read.' |
|
|
|
214 fgrep -q "$msg" < "$log_stderr" |
|
|
|
215 expect "0" "$?" "stderr must contain text $msg" |
|
|
|
216 |
|
|
|
217 "$SFEED_UPDATE" /root/.sfeed/sfeedrc >/dev/null 2> "$log_stderr" # no access |
|
|
|
218 expect "1" "$?" "exit statuscode" |
|
|
|
219 msg='Configuration file "/root/.sfeed/sfeedrc" cannot be read.' |
|
|
|
220 fgrep -q "$msg" < "$log_stderr" |
|
|
|
221 expect "0" "$?" "stderr must contain text $msg" |
|
|
|
222 |
|
|
|
223 rctmp="$(mktemp /tmp/rctmp_XXXXXXXX)" |
|
|
|
224 cp "$rc" "$rctmp" |
|
|
|
225 chmod 000 "$rctmp" # no access |
|
|
|
226 |
|
|
|
227 "$SFEED_UPDATE" "$rctmp" >/dev/null 2> "$log_stderr" # no access |
|
|
|
228 expect "1" "$?" "exit statuscode" |
|
|
|
229 if [ -r "$rctmp" ]; then |
|
|
|
230 # on haikuos test -r on a file with chmod 000 still returns 0 |
|
|
|
231 msg='does not contain a "feeds" function' |
|
|
|
232 else |
|
|
|
233 msg="Configuration file \"${rctmp}\" cannot be read." |
|
|
|
234 fi |
|
|
|
235 fgrep -q "$msg" < "$log_stderr" |
|
|
|
236 expect "0" "$?" "stderr must contain text $msg" |
|
|
|
237 |
|
|
|
238 chmod 644 "$rctmp" |
|
|
|
239 rm -f "$rctmp" "$rcempty" |
|
|
|
240 cleanup |
|
|
|
241 |
|
|
|
242 echo "test_config_invocation: test OK" >&2 |
|
|
|
243 } |
|
|
|
244 |
|
|
|
245 test_tmpdir() { |
|
|
|
246 init_test |
|
|
|
247 |
|
|
|
248 createrc > "$rc" <<! |
|
|
|
249 sfeedpath="$feedpath" |
|
|
|
250 |
|
|
|
251 feeds() { |
|
|
|
252 true |
|
|
|
253 } |
|
|
|
254 ! |
|
|
|
255 |
|
|
|
256 # NOTE: (2023-12-28) this fails on OpenIndiana, because when it doesn't have permission |
|
|
|
257 # to TMPDIR it will just silently use /tmp (this is of course stupid, failing the UNIX |
|
|
|
258 # "fail early" principle). |
|
|
|
259 TMPDIR=/noaccess "$SFEED_UPDATE" "$rc" >"$log_stdout" 2>"$log_stderr" |
|
|
|
260 expect "1" "$?" "exit statuscode" |
|
|
|
261 |
|
|
|
262 TMPDIR="/tmp" "$SFEED_UPDATE" "$rc" >"$log_stdout" 2>"$log_stderr" |
|
|
|
263 expect "0" "$?" "exit statuscode" |
|
|
|
264 |
|
|
|
265 cleanup |
|
|
|
266 |
|
|
|
267 echo "test_tmpdir: test OK" >&2 |
|
|
|
268 } |
|
|
|
269 |
|
|
|
270 test_tmpdir_cleanup() { |
|
|
|
271 init_test |
|
|
|
272 |
|
|
|
273 tmp="$(mktemp -d 'sfeed_tmpdir_XXXXXXXX')" |
|
|
|
274 |
|
|
|
275 createrc > "$rc" <<! |
|
|
|
276 sfeedpath="$feedpath" |
|
|
|
277 |
|
|
|
278 #cleanup() { |
|
|
|
279 # true |
|
|
|
280 #} |
|
|
|
281 |
|
|
|
282 feeds() { |
|
|
|
283 true |
|
|
|
284 } |
|
|
|
285 ! |
|
|
|
286 |
|
|
|
287 TMPDIR="$tmp" "$SFEED_UPDATE" "$rc" >"$log_stdout" 2>"$log_stderr" |
|
|
|
288 expect "0" "$?" "exit statuscode" |
|
|
|
289 |
|
|
|
290 # global expand, normally it should contain only one dir. |
|
|
|
291 testdir="" |
|
|
|
292 for d in "$tmp/"*/; do |
|
|
|
293 testdir="$d" |
|
|
|
294 done |
|
|
|
295 |
|
|
|
296 test -d "$testdir" |
|
|
|
297 expect "1" "$?" "feeds directory should not exist" |
|
|
|
298 |
|
|
|
299 test -f "$testdir/jobs" |
|
|
|
300 expect "1" "$?" "jobs file should not exist" |
|
|
|
301 |
|
|
|
302 rm -r "$tmp" |
|
|
|
303 cleanup |
|
|
|
304 |
|
|
|
305 echo "test_tmpdir_cleanup: test OK" >&2 |
|
|
|
306 } |
|
|
|
307 |
|
|
|
308 test_override_cleanup() { |
|
|
|
309 init_test |
|
|
|
310 |
|
|
|
311 tmp="$(mktemp -d 'sfeed_tmpdir_XXXXXXXX')" |
|
|
|
312 |
|
|
|
313 createrc > "$rc" <<! |
|
|
|
314 sfeedpath="$feedpath" |
|
|
|
315 |
|
|
|
316 cleanup() { |
|
|
|
317 true |
|
|
|
318 } |
|
|
|
319 |
|
|
|
320 feeds() { |
|
|
|
321 true |
|
|
|
322 } |
|
|
|
323 ! |
|
|
|
324 |
|
|
|
325 TMPDIR="$tmp" "$SFEED_UPDATE" "$rc" >"$log_stdout" 2>"$log_stderr" |
|
|
|
326 expect "0" "$?" "exit statuscode" |
|
|
|
327 |
|
|
|
328 # global expand, normally it should contain only one dir. |
|
|
|
329 testdir="" |
|
|
|
330 for d in "$tmp/"*/; do |
|
|
|
331 testdir="$d" |
|
|
|
332 done |
|
|
|
333 |
|
|
|
334 test -d "$testdir" |
|
|
|
335 expect "0" "$?" "feeds directory should still exist" |
|
|
|
336 |
|
|
|
337 test -f "$testdir/jobs" |
|
|
|
338 expect "0" "$?" "jobs file should still exist" |
|
|
|
339 |
|
|
|
340 test -f "$testdir/ok" |
|
|
|
341 expect "0" "$?" "status file should still exist" |
|
|
|
342 |
|
|
|
343 rm -r "$tmp" |
|
|
|
344 cleanup |
|
|
|
345 |
|
|
|
346 echo "test_override_cleanup: test OK" >&2 |
|
|
|
347 } |
|
|
|
348 |
|
|
|
349 test_parameters() { |
|
|
|
350 init_test |
|
|
|
351 |
|
|
|
352 expectfile="$(mktemp /tmp/expect_XXXXXXXX)" |
|
|
|
353 |
|
|
|
354 cat > "$expectfile" <<! |
|
|
|
355 |||| |
|
|
|
356 |feedurl|basesiteurl|encoding| |
|
|
|
357 1|||| |
|
|
|
358 2|feedurl||| |
|
|
|
359 3|feedurl|basesiteurl|| |
|
|
|
360 4|feedurl|basesiteurl|encoding| |
|
|
|
361 5|feedurl||encoding| |
|
|
|
362 6|||encoding| |
|
|
|
363 7||basesiteurl|encoding| |
|
|
|
364 8|feedurl||| |
|
|
|
365 9|feedurl|basesiteurl|| |
|
|
|
366 ! |
|
|
|
367 |
|
|
|
368 createrc > "$rc" <<! |
|
|
|
369 sfeedpath="$feedpath" |
|
|
|
370 maxjobs=1 # must be run sequential |
|
|
|
371 |
|
|
|
372 _feed() { |
|
|
|
373 printf '%s|%s|%s|%s|\n' "\$1" "\$2" "\$3" "\$4" |
|
|
|
374 } |
|
|
|
375 |
|
|
|
376 feeds() { |
|
|
|
377 # feed <name> <feedurl> [basesiteurl] [encoding] |
|
|
|
378 feed "" "" "" "" |
|
|
|
379 feed "" "feedurl" "basesiteurl" "encoding" |
|
|
|
380 feed "1" "" "" "" |
|
|
|
381 feed "2" "feedurl" "" "" |
|
|
|
382 feed "3" "feedurl" "basesiteurl" "" |
|
|
|
383 feed "4" "feedurl" "basesiteurl" "encoding" |
|
|
|
384 feed "5" "feedurl" "" "encoding" |
|
|
|
385 feed "6" "" "" "encoding" |
|
|
|
386 feed "7" "" "basesiteurl" "encoding" |
|
|
|
387 feed "8" "feedurl" |
|
|
|
388 feed "9" "feedurl" "basesiteurl" |
|
|
|
389 } |
|
|
|
390 ! |
|
|
|
391 |
|
|
|
392 "$SFEED_UPDATE" "$rc" >"$log_stdout" 2>"$log_stderr" |
|
|
|
393 expect "0" "$?" "exit statuscode" |
|
|
|
394 |
|
|
|
395 # NOTE: on OpenIndiana this writes to stdout "No differences encountered" |
|
|
|
396 # *this is of course stupid). |
|
|
|
397 diff -u "$log_stdout" "$expectfile" |
|
|
|
398 expect "0" "$?" "exit statuscode" |
|
|
|
399 |
|
|
|
400 cleanup |
|
|
|
401 rm -f "$expectfile" |
|
|
|
402 |
|
|
|
403 echo "test_parameters: test OK" >&2 |
|
|
|
404 } |
|
|
|
405 |
|
|
|
406 test_override_fetch() { |
|
|
|
407 init_test |
|
|
|
408 |
|
|
|
409 paramfile="$(mktemp /tmp/fetch_param_XXXXXXXX)" |
|
|
|
410 |
|
|
|
411 createrc > "$rc" <<! |
|
|
|
412 sfeedpath="$feedpath" |
|
|
|
413 maxjobs=1 # must be run sequential |
|
|
|
414 |
|
|
|
415 # fetch(name, url, feedfile) |
|
|
|
416 fetch() { |
|
|
|
417 # test name, url parameters. |
|
|
|
418 # dirname of feedfile is random, test only the base name which should |
|
|
|
419 # match the feed name, with some characters replaced. |
|
|
|
420 b="\${3##*/}" |
|
|
|
421 printf '%s|%s|%s|\n' "\$1" "\$2" "\$b" >> "$paramfile" |
|
|
|
422 |
|
|
|
423 case "\$1" in |
|
|
|
424 1) |
|
|
|
425 echo "<item><title>a</title></item>";; |
|
|
|
426 2) |
|
|
|
427 echo "<item><title>b</title></item>";; |
|
|
|
428 3) |
|
|
|
429 echo "<item><title>c</title></item>";; |
|
|
|
430 # test / in names, allowed, but path name for feed itself are replaced to underscore. |
|
|
|
431 "funky/name") |
|
|
|
432 echo "<item><title>d</title></item>";; |
|
|
|
433 "funky*name") |
|
|
|
434 echo "<item><title>e</title></item>";; |
|
|
|
435 # test spaces in names |
|
|
|
436 "name with spaces") |
|
|
|
437 echo "<item><title>f</title></item>";; |
|
|
|
438 esac |
|
|
|
439 } |
|
|
|
440 |
|
|
|
441 feeds() { |
|
|
|
442 # feed <name> <feedurl> [basesiteurl] [encoding] |
|
|
|
443 feed "1" "file:///dev/null1" |
|
|
|
444 feed "2" "file:///dev/null2" |
|
|
|
445 feed "3" "file:///dev/null3" |
|
|
|
446 feed "funky/name" "file:///dev/null4" |
|
|
|
447 feed "funky*name" "file:///dev/null5" |
|
|
|
448 feed "name with spaces" "file:///dev/null6" |
|
|
|
449 } |
|
|
|
450 ! |
|
|
|
451 |
|
|
|
452 "$SFEED_UPDATE" "$rc" >"$log_stdout" 2>"$log_stderr" |
|
|
|
453 expect "0" "$?" "exit statuscode" |
|
|
|
454 |
|
|
|
455 result=$(cut -f 2 "$feedpath/1" "$feedpath/2" "$feedpath/3" \ |
|
|
|
456 "$feedpath/funky_name" "$feedpath/funky*name" "$feedpath/name with spaces" | tr -d '\n') |
|
|
|
457 expect "abcdef" "$result" "results of feed files" |
|
|
|
458 |
|
|
|
459 paramstr=$(cat "$paramfile" | tr -d '\n') |
|
|
|
460 expect '1|file:///dev/null1|1|2|file:///dev/null2|2|3|file:///dev/null3|3|funky/name|file:///dev/null4|funky_name|funky*name|file:///dev/null5|funky*name|name with spaces|file:///dev/null6|name with spaces|'\ |
|
|
|
461 "$paramstr" "test parameters" |
|
|
|
462 |
|
|
|
463 cleanup |
|
|
|
464 rm -f "$paramfile" |
|
|
|
465 |
|
|
|
466 echo "test_override_fetch: test OK" >&2 |
|
|
|
467 } |
|
|
|
468 |
|
|
|
469 test_override_convertencoding() { |
|
|
|
470 init_test |
|
|
|
471 |
|
|
|
472 paramfile="$(mktemp /tmp/convertencoding_param_XXXXXXXX)" |
|
|
|
473 |
|
|
|
474 createrc > "$rc" <<! |
|
|
|
475 sfeedpath="$feedpath" |
|
|
|
476 maxjobs=1 |
|
|
|
477 |
|
|
|
478 fetch() { |
|
|
|
479 echo |
|
|
|
480 } |
|
|
|
481 |
|
|
|
482 parse() { |
|
|
|
483 cat |
|
|
|
484 } |
|
|
|
485 |
|
|
|
486 # convertencoding(name, from, to) |
|
|
|
487 convertencoding() { |
|
|
|
488 printf '%s|%s|%s|\n' "\$1" "\$2" "\$3" >> "$paramfile" |
|
|
|
489 |
|
|
|
490 # to parameter is always "utf-8". |
|
|
|
491 test "\$3" != "utf-8" && return 1 |
|
|
|
492 |
|
|
|
493 case "\$1" in |
|
|
|
494 1) |
|
|
|
495 echo "a";; |
|
|
|
496 2) |
|
|
|
497 echo "b";; |
|
|
|
498 3) |
|
|
|
499 echo "c";; |
|
|
|
500 4) |
|
|
|
501 echo "d";; |
|
|
|
502 5) |
|
|
|
503 echo "e";; |
|
|
|
504 esac |
|
|
|
505 } |
|
|
|
506 |
|
|
|
507 feeds() { |
|
|
|
508 # feed <name> <feedurl> [basesiteurl] [encoding] |
|
|
|
509 feed "1" "file:///dev/null1" "" "" |
|
|
|
510 feed "2" "file:///dev/null2" "" "utf-8" |
|
|
|
511 feed "3" "file:///dev/null3" "" "iso-8859-1" |
|
|
|
512 feed "4" "file:///dev/null4" "" "utf-69" |
|
|
|
513 feed "5" "file:///dev/null5" "" "from-utf-6" |
|
|
|
514 } |
|
|
|
515 ! |
|
|
|
516 |
|
|
|
517 "$SFEED_UPDATE" "$rc" >"$log_stdout" 2>"$log_stderr" |
|
|
|
518 expect "0" "$?" "exit statuscode" |
|
|
|
519 |
|
|
|
520 linecount=$(wc -l < "$log_stdout") |
|
|
|
521 linecount=$((linecount+0)) |
|
|
|
522 expect "5" "$linecount" "5 lines should be written to stdout" |
|
|
|
523 |
|
|
|
524 linecount=$(wc -l < "$log_stderr") |
|
|
|
525 linecount=$((linecount+0)) |
|
|
|
526 expect "0" "$linecount" "0 line should be written to stderr" |
|
|
|
527 |
|
|
|
528 result=$(cut -f 2 "$feedpath/1" "$feedpath/2" "$feedpath/3" \ |
|
|
|
529 "$feedpath/4" "$feedpath/5" | tr -d '\n') |
|
|
|
530 expect "abcde" "$result" "results of feed files" |
|
|
|
531 |
|
|
|
532 paramstr=$(cat "$paramfile" | tr -d '\n') |
|
|
|
533 expect '1||utf-8|2|utf-8|utf-8|3|iso-8859-1|utf-8|4|utf-69|utf-8|5|from-utf-6|utf-8|'\ |
|
|
|
534 "$paramstr" "test parameters" |
|
|
|
535 |
|
|
|
536 cleanup |
|
|
|
537 rm -f "$paramfile" |
|
|
|
538 |
|
|
|
539 echo "test_override_convertencoding: test OK" >&2 |
|
|
|
540 } |
|
|
|
541 |
|
|
|
542 test_fail_fetch() { |
|
|
|
543 init_test |
|
|
|
544 |
|
|
|
545 createrc > "$rc" <<! |
|
|
|
546 sfeedpath="$feedpath" |
|
|
|
547 maxjobs=1 |
|
|
|
548 |
|
|
|
549 fetch() { |
|
|
|
550 test "\$1" = "2" && return 1 |
|
|
|
551 true |
|
|
|
552 } |
|
|
|
553 |
|
|
|
554 feeds() { |
|
|
|
555 # feed <name> <feedurl> [basesiteurl] [encoding] |
|
|
|
556 feed "1" "file:///dev/null" |
|
|
|
557 feed "2" "file:///dev/null" |
|
|
|
558 feed "3" "file:///dev/null" |
|
|
|
559 } |
|
|
|
560 ! |
|
|
|
561 |
|
|
|
562 "$SFEED_UPDATE" "$rc" >"$log_stdout" 2> "$log_stderr" |
|
|
|
563 expect "1" "$?" "exit statuscode" |
|
|
|
564 |
|
|
|
565 linecount=$(wc -l < "$log_stdout") |
|
|
|
566 linecount=$((linecount+0)) |
|
|
|
567 expect "2" "$linecount" "2 lines should be written to stdout" |
|
|
|
568 |
|
|
|
569 linecount=$(wc -l < "$log_stderr") |
|
|
|
570 linecount=$((linecount+0)) |
|
|
|
571 expect "1" "$linecount" "1 line should be written to stderr" |
|
|
|
572 |
|
|
|
573 grep -q "] 2 .* FAIL (FETCH)" < "$log_stderr" |
|
|
|
574 expect "0" "$?" 'stderr should contain "FAIL (FETCH)"' |
|
|
|
575 |
|
|
|
576 test -d "$feedpath" |
|
|
|
577 expect "0" "$?" "directory should exist: $feedpath" |
|
|
|
578 |
|
|
|
579 for i in 1 2 3; do |
|
|
|
580 f="$feedpath/$i" |
|
|
|
581 test -f "$f" |
|
|
|
582 expect "0" "$?" "file should exist: $f" |
|
|
|
583 done |
|
|
|
584 |
|
|
|
585 cleanup |
|
|
|
586 |
|
|
|
587 echo "test_fail_fetch: test OK" >&2 |
|
|
|
588 } |
|
|
|
589 |
|
|
|
590 test_fail_convertencoding() { |
|
|
|
591 init_test |
|
|
|
592 |
|
|
|
593 createrc > "$rc" <<! |
|
|
|
594 sfeedpath="$feedpath" |
|
|
|
595 maxjobs=1 |
|
|
|
596 |
|
|
|
597 convertencoding() { |
|
|
|
598 test "\$1" = "2" && return 1 |
|
|
|
599 true |
|
|
|
600 } |
|
|
|
601 |
|
|
|
602 feeds() { |
|
|
|
603 # feed <name> <feedurl> [basesiteurl] [encoding] |
|
|
|
604 feed "1" "file:///dev/null" |
|
|
|
605 feed "2" "file:///dev/null" |
|
|
|
606 feed "3" "file:///dev/null" |
|
|
|
607 } |
|
|
|
608 ! |
|
|
|
609 |
|
|
|
610 "$SFEED_UPDATE" "$rc" >"$log_stdout" 2> "$log_stderr" |
|
|
|
611 expect "1" "$?" "exit statuscode" |
|
|
|
612 |
|
|
|
613 linecount=$(wc -l < "$log_stdout") |
|
|
|
614 linecount=$((linecount+0)) |
|
|
|
615 expect "2" "$linecount" "2 lines should be written to stdout" |
|
|
|
616 |
|
|
|
617 linecount=$(wc -l < "$log_stderr") |
|
|
|
618 linecount=$((linecount+0)) |
|
|
|
619 expect "1" "$linecount" "1 line should be written to stderr" |
|
|
|
620 |
|
|
|
621 grep -q "] 2 .* FAIL (ENCODING)" < "$log_stderr" |
|
|
|
622 expect "0" "$?" 'stderr should contain "FAIL (ENCODING)"' |
|
|
|
623 |
|
|
|
624 test -d "$feedpath" |
|
|
|
625 expect "0" "$?" "directory should exist: $feedpath" |
|
|
|
626 |
|
|
|
627 for i in 1 2 3; do |
|
|
|
628 f="$feedpath/$i" |
|
|
|
629 test -f "$f" |
|
|
|
630 expect "0" "$?" "file should exist: $f" |
|
|
|
631 done |
|
|
|
632 |
|
|
|
633 cleanup |
|
|
|
634 |
|
|
|
635 echo "test_fail_convertencoding: test OK" >&2 |
|
|
|
636 } |
|
|
|
637 |
|
|
|
638 test_override_parse() { |
|
|
|
639 init_test |
|
|
|
640 |
|
|
|
641 paramfile="$(mktemp /tmp/parse_param_XXXXXXXX)" |
|
|
|
642 |
|
|
|
643 createrc > "$rc" <<! |
|
|
|
644 sfeedpath="$feedpath" |
|
|
|
645 maxjobs=1 |
|
|
|
646 |
|
|
|
647 fetch() { |
|
|
|
648 echo |
|
|
|
649 } |
|
|
|
650 |
|
|
|
651 convertencoding() { |
|
|
|
652 cat |
|
|
|
653 } |
|
|
|
654 |
|
|
|
655 # parse(name, feedurl, basesiteurl) |
|
|
|
656 parse() { |
|
|
|
657 printf '%s|%s|%s|\n' "\$1" "\$2" "\$3" >> "$paramfile" |
|
|
|
658 |
|
|
|
659 echo "\$1 title #\$1" |
|
|
|
660 } |
|
|
|
661 |
|
|
|
662 feeds() { |
|
|
|
663 # feed <name> <feedurl> [basesiteurl] [encoding] |
|
|
|
664 feed "1" "file:///dev/null1" "" "" |
|
|
|
665 feed "2" "file:///dev/null2" "basesiteurl" "utf-8" |
|
|
|
666 feed "3" "file:///dev/null3" "" "iso-8859-1" |
|
|
|
667 feed "4" "file:///dev/null4" "" "utf-69" |
|
|
|
668 feed "5" "file:///dev/null5" "" "from-utf-6" |
|
|
|
669 } |
|
|
|
670 ! |
|
|
|
671 |
|
|
|
672 "$SFEED_UPDATE" "$rc" >"$log_stdout" 2>"$log_stderr" |
|
|
|
673 expect "0" "$?" "exit statuscode" |
|
|
|
674 |
|
|
|
675 linecount=$(wc -l < "$log_stdout") |
|
|
|
676 linecount=$((linecount+0)) |
|
|
|
677 expect "5" "$linecount" "5 lines should be written to stdout" |
|
|
|
678 |
|
|
|
679 linecount=$(wc -l < "$log_stderr") |
|
|
|
680 linecount=$((linecount+0)) |
|
|
|
681 expect "0" "$linecount" "0 line should be written to stderr" |
|
|
|
682 |
|
|
|
683 result=$(cat "$feedpath/1" "$feedpath/2" "$feedpath/3" \ |
|
|
|
684 "$feedpath/4" "$feedpath/5" | tr -d '\n') |
|
|
|
685 expect "1 title #12 title #23 title #34 title #45 title #5"\ |
|
|
|
686 "$result" "results of feed files" |
|
|
|
687 |
|
|
|
688 paramstr=$(cat "$paramfile" | tr -d '\n') |
|
|
|
689 expect '1|file:///dev/null1|file:///dev/null1|2|file:///dev/null2|basesiteurl|3|file:///dev/null3|file:///dev/null3|4|file:///dev/null4|file:///dev/null4|5|file:///dev/null5|file:///dev/null5|'\ |
|
|
|
690 "$paramstr" "test parameters" |
|
|
|
691 |
|
|
|
692 cleanup |
|
|
|
693 rm -f "$paramfile" |
|
|
|
694 |
|
|
|
695 echo "test_override_parse: test OK" >&2 |
|
|
|
696 } |
|
|
|
697 |
|
|
|
698 test_fail_parse() { |
|
|
|
699 init_test |
|
|
|
700 |
|
|
|
701 createrc > "$rc" <<! |
|
|
|
702 sfeedpath="$feedpath" |
|
|
|
703 maxjobs=1 |
|
|
|
704 |
|
|
|
705 parse() { |
|
|
|
706 test "\$1" = "2" && return 1 |
|
|
|
707 true |
|
|
|
708 } |
|
|
|
709 |
|
|
|
710 feeds() { |
|
|
|
711 # feed <name> <feedurl> [basesiteurl] [encoding] |
|
|
|
712 feed "1" "file:///dev/null" |
|
|
|
713 feed "2" "file:///dev/null" |
|
|
|
714 feed "3" "file:///dev/null" |
|
|
|
715 } |
|
|
|
716 ! |
|
|
|
717 |
|
|
|
718 "$SFEED_UPDATE" "$rc" >"$log_stdout" 2> "$log_stderr" |
|
|
|
719 expect "1" "$?" "exit statuscode" |
|
|
|
720 |
|
|
|
721 linecount=$(wc -l < "$log_stdout") |
|
|
|
722 linecount=$((linecount+0)) |
|
|
|
723 expect "2" "$linecount" "2 lines should be written to stdout" |
|
|
|
724 |
|
|
|
725 linecount=$(wc -l < "$log_stderr") |
|
|
|
726 linecount=$((linecount+0)) |
|
|
|
727 expect "1" "$linecount" "1 line should be written to stderr" |
|
|
|
728 |
|
|
|
729 grep -q "] 2 .* FAIL (PARSE)" < "$log_stderr" |
|
|
|
730 expect "0" "$?" 'stderr should contain "FAIL (PARSE)"' |
|
|
|
731 |
|
|
|
732 test -d "$feedpath" |
|
|
|
733 expect "0" "$?" "directory should exist: $feedpath" |
|
|
|
734 |
|
|
|
735 for i in 1 2 3; do |
|
|
|
736 f="$feedpath/$i" |
|
|
|
737 test -f "$f" |
|
|
|
738 expect "0" "$?" "file should exist: $f" |
|
|
|
739 done |
|
|
|
740 |
|
|
|
741 cleanup |
|
|
|
742 |
|
|
|
743 echo "test_fail_parse: test OK" >&2 |
|
|
|
744 } |
|
|
|
745 |
|
|
|
746 test_override_filter() { |
|
|
|
747 init_test |
|
|
|
748 |
|
|
|
749 paramfile="$(mktemp /tmp/filter_param_XXXXXXXX)" |
|
|
|
750 |
|
|
|
751 createrc > "$rc" <<! |
|
|
|
752 sfeedpath="$feedpath" |
|
|
|
753 maxjobs=1 |
|
|
|
754 |
|
|
|
755 fetch() { |
|
|
|
756 echo "\$1" |
|
|
|
757 } |
|
|
|
758 |
|
|
|
759 convertencoding() { |
|
|
|
760 cat |
|
|
|
761 } |
|
|
|
762 |
|
|
|
763 # filter(name) |
|
|
|
764 filter() { |
|
|
|
765 printf '%s|\n' "\$1" >> "$paramfile" |
|
|
|
766 |
|
|
|
767 sed 's@^@BLA@g' |
|
|
|
768 } |
|
|
|
769 |
|
|
|
770 parse() { |
|
|
|
771 cat |
|
|
|
772 } |
|
|
|
773 |
|
|
|
774 feeds() { |
|
|
|
775 # feed <name> <feedurl> [basesiteurl] [encoding] |
|
|
|
776 feed "1" "file:///dev/null1" "" "" |
|
|
|
777 feed "2" "file:///dev/null2" "basesiteurl" "utf-8" |
|
|
|
778 feed "3" "file:///dev/null3" "" "iso-8859-1" |
|
|
|
779 feed "4" "file:///dev/null4" "" "utf-69" |
|
|
|
780 feed "5" "file:///dev/null5" "" "from-utf-6" |
|
|
|
781 } |
|
|
|
782 ! |
|
|
|
783 |
|
|
|
784 "$SFEED_UPDATE" "$rc" >"$log_stdout" 2>"$log_stderr" |
|
|
|
785 expect "0" "$?" "exit statuscode" |
|
|
|
786 |
|
|
|
787 linecount=$(wc -l < "$log_stdout") |
|
|
|
788 linecount=$((linecount+0)) |
|
|
|
789 expect "5" "$linecount" "5 lines should be written to stdout" |
|
|
|
790 |
|
|
|
791 linecount=$(wc -l < "$log_stderr") |
|
|
|
792 linecount=$((linecount+0)) |
|
|
|
793 expect "0" "$linecount" "0 line should be written to stderr" |
|
|
|
794 |
|
|
|
795 result=$(cat "$feedpath/1" "$feedpath/2" "$feedpath/3" \ |
|
|
|
796 "$feedpath/4" "$feedpath/5" | tr -d '\n') |
|
|
|
797 expect 'BLA1BLA2BLA3BLA4BLA5'\ |
|
|
|
798 "$result" "results of feed files" |
|
|
|
799 |
|
|
|
800 paramstr=$(cat "$paramfile" | tr -d '\n') |
|
|
|
801 expect '1|2|3|4|5|'\ |
|
|
|
802 "$paramstr" "test parameters" |
|
|
|
803 |
|
|
|
804 cleanup |
|
|
|
805 rm -f "$paramfile" |
|
|
|
806 |
|
|
|
807 echo "test_override_filter: test OK" >&2 |
|
|
|
808 } |
|
|
|
809 |
|
|
|
810 test_fail_filter() { |
|
|
|
811 init_test |
|
|
|
812 |
|
|
|
813 createrc > "$rc" <<! |
|
|
|
814 sfeedpath="$feedpath" |
|
|
|
815 maxjobs=1 |
|
|
|
816 |
|
|
|
817 filter() { |
|
|
|
818 test "\$1" = "2" && return 1 |
|
|
|
819 true |
|
|
|
820 } |
|
|
|
821 |
|
|
|
822 feeds() { |
|
|
|
823 # feed <name> <feedurl> [basesiteurl] [encoding] |
|
|
|
824 feed "1" "file:///dev/null" |
|
|
|
825 feed "2" "file:///dev/null" |
|
|
|
826 feed "3" "file:///dev/null" |
|
|
|
827 } |
|
|
|
828 ! |
|
|
|
829 |
|
|
|
830 "$SFEED_UPDATE" "$rc" >"$log_stdout" 2> "$log_stderr" |
|
|
|
831 expect "1" "$?" "exit statuscode" |
|
|
|
832 |
|
|
|
833 linecount=$(wc -l < "$log_stdout") |
|
|
|
834 linecount=$((linecount+0)) |
|
|
|
835 expect "2" "$linecount" "2 lines should be written to stdout" |
|
|
|
836 |
|
|
|
837 linecount=$(wc -l < "$log_stderr") |
|
|
|
838 linecount=$((linecount+0)) |
|
|
|
839 expect "1" "$linecount" "1 line should be written to stderr" |
|
|
|
840 |
|
|
|
841 grep -q "] 2 .* FAIL (FILTER)" < "$log_stderr" |
|
|
|
842 expect "0" "$?" 'stderr should contain "FAIL (FILTER)"' |
|
|
|
843 |
|
|
|
844 test -d "$feedpath" |
|
|
|
845 expect "0" "$?" "directory should exist: $feedpath" |
|
|
|
846 |
|
|
|
847 for i in 1 2 3; do |
|
|
|
848 f="$feedpath/$i" |
|
|
|
849 test -f "$f" |
|
|
|
850 expect "0" "$?" "file should exist: $f" |
|
|
|
851 done |
|
|
|
852 |
|
|
|
853 cleanup |
|
|
|
854 |
|
|
|
855 echo "test_fail_filter: test OK" >&2 |
|
|
|
856 } |
|
|
|
857 |
|
|
|
858 test_nothing_to_merge() { |
|
|
|
859 init_test |
|
|
|
860 |
|
|
|
861 createrc > "$rc" <<! |
|
|
|
862 sfeedpath="$feedpath" |
|
|
|
863 maxjobs=1 |
|
|
|
864 |
|
|
|
865 # filter must output some data, otherwise there is nothing to merge. |
|
|
|
866 #filter() { |
|
|
|
867 # echo a |
|
|
|
868 #} |
|
|
|
869 |
|
|
|
870 merge() { |
|
|
|
871 test "\$1" = "2" && return 1 |
|
|
|
872 return 0 |
|
|
|
873 } |
|
|
|
874 |
|
|
|
875 feeds() { |
|
|
|
876 # feed <name> <feedurl> [basesiteurl] [encoding] |
|
|
|
877 feed "1" "file:///dev/null" |
|
|
|
878 feed "2" "file:///dev/null" |
|
|
|
879 feed "3" "file:///dev/null" |
|
|
|
880 } |
|
|
|
881 ! |
|
|
|
882 |
|
|
|
883 # feed 2 isn't called (nothing to merge) so should return exit 0. |
|
|
|
884 "$SFEED_UPDATE" "$rc" >"$log_stdout" 2> "$log_stderr" |
|
|
|
885 expect "0" "$?" "exit statuscode" |
|
|
|
886 |
|
|
|
887 linecount=$(wc -l < "$log_stdout") |
|
|
|
888 linecount=$((linecount+0)) |
|
|
|
889 expect "3" "$linecount" "3 lines should be written to stdout" |
|
|
|
890 |
|
|
|
891 linecount=$(wc -l < "$log_stderr") |
|
|
|
892 linecount=$((linecount+0)) |
|
|
|
893 expect "0" "$linecount" "0 line should be written to stderr" |
|
|
|
894 |
|
|
|
895 grep -q "] 2 .* FAIL (MERGE)" < "$log_stderr" |
|
|
|
896 expect "1" "$?" 'stderr should not contain "FAIL (MERGE)"' |
|
|
|
897 |
|
|
|
898 test -d "$feedpath" |
|
|
|
899 expect "0" "$?" "directory should exist: $feedpath" |
|
|
|
900 |
|
|
|
901 for i in 1 2 3; do |
|
|
|
902 f="$feedpath/$i" |
|
|
|
903 test -f "$f" |
|
|
|
904 expect "0" "$?" "file should exist: $f" |
|
|
|
905 done |
|
|
|
906 |
|
|
|
907 cleanup |
|
|
|
908 |
|
|
|
909 echo "test_nothing_to_merge: test OK" >&2 |
|
|
|
910 } |
|
|
|
911 |
|
|
|
912 test_override_merge() { |
|
|
|
913 init_test |
|
|
|
914 |
|
|
|
915 paramfile="$(mktemp /tmp/merge_param_XXXXXXXX)" |
|
|
|
916 |
|
|
|
917 createrc > "$rc" <<! |
|
|
|
918 sfeedpath="$feedpath" |
|
|
|
919 maxjobs=1 |
|
|
|
920 |
|
|
|
921 # merge(name, oldfile, newfile) |
|
|
|
922 merge() { |
|
|
|
923 # dirname of feedfile is random, test only the base name which should |
|
|
|
924 # match the feed name, with some characters replaced. |
|
|
|
925 b2="\${2##*/}" |
|
|
|
926 b3="\${3##*/}" |
|
|
|
927 |
|
|
|
928 printf '%s|%s|%s|\n' "\$1" "\$b2" "\$b3" >> "$paramfile" |
|
|
|
929 |
|
|
|
930 cat "\$2" "\$3" |
|
|
|
931 } |
|
|
|
932 |
|
|
|
933 order() { |
|
|
|
934 cat |
|
|
|
935 } |
|
|
|
936 |
|
|
|
937 fetch() { |
|
|
|
938 echo "\$1" |
|
|
|
939 } |
|
|
|
940 |
|
|
|
941 convertencoding() { |
|
|
|
942 cat |
|
|
|
943 } |
|
|
|
944 |
|
|
|
945 filter() { |
|
|
|
946 cat |
|
|
|
947 } |
|
|
|
948 |
|
|
|
949 parse() { |
|
|
|
950 cat |
|
|
|
951 } |
|
|
|
952 |
|
|
|
953 feeds() { |
|
|
|
954 # feed <name> <feedurl> [basesiteurl] [encoding] |
|
|
|
955 feed "1" "file:///dev/null1" "" "" |
|
|
|
956 feed "2" "file:///dev/null2" "basesiteurl" "utf-8" |
|
|
|
957 feed "3" "file:///dev/null3" "" "iso-8859-1" |
|
|
|
958 feed "name with / in it" "file:///dev/null4" "" "utf-69" |
|
|
|
959 feed "name with spaces" "file:///dev/null5" "" "from-utf-6" |
|
|
|
960 } |
|
|
|
961 ! |
|
|
|
962 |
|
|
|
963 "$SFEED_UPDATE" "$rc" >"$log_stdout" 2>"$log_stderr" |
|
|
|
964 expect "0" "$?" "exit statuscode" |
|
|
|
965 |
|
|
|
966 linecount=$(wc -l < "$log_stdout") |
|
|
|
967 linecount=$((linecount+0)) |
|
|
|
968 expect "5" "$linecount" "5 lines should be written to stdout" |
|
|
|
969 |
|
|
|
970 linecount=$(wc -l < "$log_stderr") |
|
|
|
971 linecount=$((linecount+0)) |
|
|
|
972 expect "0" "$linecount" "0 line should be written to stderr" |
|
|
|
973 |
|
|
|
974 result=$(cat "$feedpath/1" "$feedpath/2" "$feedpath/3" \ |
|
|
|
975 "$feedpath/name with _ in it" "$feedpath/name with spaces" | tr -d '\n') |
|
|
|
976 expect '123name with / in itname with spaces'\ |
|
|
|
977 "$result" "results of feed files" |
|
|
|
978 |
|
|
|
979 paramstr=$(cat "$paramfile" | tr -d '\n') |
|
|
|
980 expect '1|1|1.filter|2|2|2.filter|3|3|3.filter|name with / in it|name with _ in it|name with _ in it.filter|name with spaces|name with spaces|name with spaces.filter|'\ |
|
|
|
981 "$paramstr" "test parameters" |
|
|
|
982 |
|
|
|
983 # run another, should concat the results (in merge function). |
|
|
|
984 "$SFEED_UPDATE" "$rc" >"$log_stdout" 2>"$log_stderr" |
|
|
|
985 expect "0" "$?" "exit statuscode" |
|
|
|
986 |
|
|
|
987 result=$(cat "$feedpath/1" "$feedpath/2" "$feedpath/3" \ |
|
|
|
988 "$feedpath/name with _ in it" "$feedpath/name with spaces" | tr -d '\n') |
|
|
|
989 expect '112233name with / in itname with / in itname with spacesname with spaces'\ |
|
|
|
990 "$result" "results of feed files" |
|
|
|
991 |
|
|
|
992 cleanup |
|
|
|
993 rm -f "$paramfile" |
|
|
|
994 |
|
|
|
995 echo "test_override_merge: test OK" >&2 |
|
|
|
996 } |
|
|
|
997 |
|
|
|
998 test_fail_merge() { |
|
|
|
999 init_test |
|
|
|
1000 |
|
|
|
1001 createrc > "$rc" <<! |
|
|
|
1002 sfeedpath="$feedpath" |
|
|
|
1003 maxjobs=1 |
|
|
|
1004 |
|
|
|
1005 # filter must output some data, otherwise there is nothing to merge. |
|
|
|
1006 filter() { |
|
|
|
1007 echo a |
|
|
|
1008 } |
|
|
|
1009 |
|
|
|
1010 merge() { |
|
|
|
1011 test "\$1" = "2" && return 1 |
|
|
|
1012 return 0 |
|
|
|
1013 } |
|
|
|
1014 |
|
|
|
1015 feeds() { |
|
|
|
1016 # feed <name> <feedurl> [basesiteurl] [encoding] |
|
|
|
1017 feed "1" "file:///dev/null" |
|
|
|
1018 feed "2" "file:///dev/null" |
|
|
|
1019 feed "3" "file:///dev/null" |
|
|
|
1020 } |
|
|
|
1021 ! |
|
|
|
1022 |
|
|
|
1023 "$SFEED_UPDATE" "$rc" >"$log_stdout" 2> "$log_stderr" |
|
|
|
1024 expect "1" "$?" "exit statuscode" |
|
|
|
1025 |
|
|
|
1026 linecount=$(wc -l < "$log_stdout") |
|
|
|
1027 linecount=$((linecount+0)) |
|
|
|
1028 expect "2" "$linecount" "2 lines should be written to stdout" |
|
|
|
1029 |
|
|
|
1030 linecount=$(wc -l < "$log_stderr") |
|
|
|
1031 linecount=$((linecount+0)) |
|
|
|
1032 expect "1" "$linecount" "1 line should be written to stderr" |
|
|
|
1033 |
|
|
|
1034 grep -q "] 2 .* FAIL (MERGE)" < "$log_stderr" |
|
|
|
1035 expect "0" "$?" 'stderr should contain "FAIL (MERGE)"' |
|
|
|
1036 |
|
|
|
1037 test -d "$feedpath" |
|
|
|
1038 expect "0" "$?" "directory should exist: $feedpath" |
|
|
|
1039 |
|
|
|
1040 for i in 1 2 3; do |
|
|
|
1041 f="$feedpath/$i" |
|
|
|
1042 test -f "$f" |
|
|
|
1043 expect "0" "$?" "file should exist: $f" |
|
|
|
1044 done |
|
|
|
1045 |
|
|
|
1046 cleanup |
|
|
|
1047 |
|
|
|
1048 echo "test_fail_merge: test OK" >&2 |
|
|
|
1049 } |
|
|
|
1050 |
|
|
|
1051 test_override_order() { |
|
|
|
1052 init_test |
|
|
|
1053 |
|
|
|
1054 paramfile="$(mktemp /tmp/order_param_XXXXXXXX)" |
|
|
|
1055 |
|
|
|
1056 createrc > "$rc" <<! |
|
|
|
1057 sfeedpath="$feedpath" |
|
|
|
1058 maxjobs=1 |
|
|
|
1059 |
|
|
|
1060 fetch() { |
|
|
|
1061 echo |
|
|
|
1062 } |
|
|
|
1063 |
|
|
|
1064 convertencoding() { |
|
|
|
1065 cat |
|
|
|
1066 } |
|
|
|
1067 |
|
|
|
1068 parse() { |
|
|
|
1069 echo "9\$1 title #\$1" |
|
|
|
1070 echo "7\$1 title #\$1" |
|
|
|
1071 echo "8\$1 title #\$1" |
|
|
|
1072 } |
|
|
|
1073 |
|
|
|
1074 filter() { |
|
|
|
1075 cat |
|
|
|
1076 } |
|
|
|
1077 |
|
|
|
1078 merge() { |
|
|
|
1079 cat "\$3" |
|
|
|
1080 } |
|
|
|
1081 |
|
|
|
1082 # order(name) |
|
|
|
1083 order() { |
|
|
|
1084 printf '%s|\n' "\$1" >> "$paramfile" |
|
|
|
1085 |
|
|
|
1086 sort -k1,1rn |
|
|
|
1087 } |
|
|
|
1088 |
|
|
|
1089 feeds() { |
|
|
|
1090 # feed <name> <feedurl> [basesiteurl] [encoding] |
|
|
|
1091 feed "5" "file:///dev/null5" "" "from-utf-6" |
|
|
|
1092 feed "2" "file:///dev/null2" "basesiteurl" "utf-8" |
|
|
|
1093 feed "1" "file:///dev/null1" "" "" |
|
|
|
1094 feed "3" "file:///dev/null3" "" "iso-8859-1" |
|
|
|
1095 feed "4" "file:///dev/null4" "" "utf-69" |
|
|
|
1096 |
|
|
|
1097 } |
|
|
|
1098 ! |
|
|
|
1099 |
|
|
|
1100 "$SFEED_UPDATE" "$rc" >"$log_stdout" 2>"$log_stderr" |
|
|
|
1101 expect "0" "$?" "exit statuscode" |
|
|
|
1102 |
|
|
|
1103 linecount=$(wc -l < "$log_stdout") |
|
|
|
1104 linecount=$((linecount+0)) |
|
|
|
1105 expect "5" "$linecount" "5 lines should be written to stdout" |
|
|
|
1106 |
|
|
|
1107 linecount=$(wc -l < "$log_stderr") |
|
|
|
1108 linecount=$((linecount+0)) |
|
|
|
1109 expect "0" "$linecount" "0 line should be written to stderr" |
|
|
|
1110 |
|
|
|
1111 result=$(cat "$feedpath/1" | tr -d '\n') |
|
|
|
1112 expect '91 title #181 title #171 title #1'\ |
|
|
|
1113 "$result" "results of feed files" |
|
|
|
1114 |
|
|
|
1115 paramstr=$(cat "$paramfile" | tr -d '\n') |
|
|
|
1116 expect '5|2|1|3|4|'\ |
|
|
|
1117 "$paramstr" "test parameters" |
|
|
|
1118 |
|
|
|
1119 cleanup |
|
|
|
1120 rm -f "$paramfile" |
|
|
|
1121 |
|
|
|
1122 echo "test_override_order: test OK" >&2 |
|
|
|
1123 } |
|
|
|
1124 |
|
|
|
1125 test_fail_order() { |
|
|
|
1126 init_test |
|
|
|
1127 |
|
|
|
1128 createrc > "$rc" <<! |
|
|
|
1129 sfeedpath="$feedpath" |
|
|
|
1130 maxjobs=1 |
|
|
|
1131 |
|
|
|
1132 # filter must output some data, otherwise there is nothing to merge. |
|
|
|
1133 filter() { |
|
|
|
1134 echo a |
|
|
|
1135 } |
|
|
|
1136 |
|
|
|
1137 order() { |
|
|
|
1138 test "\$1" = "2" && return 1 |
|
|
|
1139 true |
|
|
|
1140 } |
|
|
|
1141 |
|
|
|
1142 feeds() { |
|
|
|
1143 # feed <name> <feedurl> [basesiteurl] [encoding] |
|
|
|
1144 feed "1" "file:///dev/null" |
|
|
|
1145 feed "2" "file:///dev/null" |
|
|
|
1146 feed "3" "file:///dev/null" |
|
|
|
1147 } |
|
|
|
1148 ! |
|
|
|
1149 |
|
|
|
1150 "$SFEED_UPDATE" "$rc" >"$log_stdout" 2> "$log_stderr" |
|
|
|
1151 expect "1" "$?" "exit statuscode" |
|
|
|
1152 |
|
|
|
1153 linecount=$(wc -l < "$log_stdout") |
|
|
|
1154 linecount=$((linecount+0)) |
|
|
|
1155 expect "2" "$linecount" "2 lines should be written to stdout" |
|
|
|
1156 |
|
|
|
1157 linecount=$(wc -l < "$log_stderr") |
|
|
|
1158 linecount=$((linecount+0)) |
|
|
|
1159 expect "1" "$linecount" "1 line should be written to stderr" |
|
|
|
1160 |
|
|
|
1161 grep -q "] 2 .* FAIL (ORDER)" < "$log_stderr" |
|
|
|
1162 expect "0" "$?" 'stderr should contain "FAIL (ORDER)"' |
|
|
|
1163 |
|
|
|
1164 test -d "$feedpath" |
|
|
|
1165 expect "0" "$?" "directory should exist: $feedpath" |
|
|
|
1166 |
|
|
|
1167 for i in 1 2 3; do |
|
|
|
1168 f="$feedpath/$i" |
|
|
|
1169 test -f "$f" |
|
|
|
1170 expect "0" "$?" "file should exist: $f" |
|
|
|
1171 done |
|
|
|
1172 |
|
|
|
1173 cleanup |
|
|
|
1174 |
|
|
|
1175 echo "test_fail_order: test OK" >&2 |
|
|
|
1176 } |
|
|
|
1177 |
|
|
|
1178 # basic test for SFEED_UPDATE_INCLUDE=1 |
|
|
|
1179 test_include() { |
|
|
|
1180 init_test |
|
|
|
1181 |
|
|
|
1182 script="$(mktemp)" |
|
|
|
1183 |
|
|
|
1184 createrc > "$rc" <<! |
|
|
|
1185 sfeedpath="$feedpath" |
|
|
|
1186 maxjobs=1 # must be run sequential |
|
|
|
1187 |
|
|
|
1188 feeds() { |
|
|
|
1189 # feed <name> <feedurl> [basesiteurl] [encoding] |
|
|
|
1190 feed "1" "file:///dev/null" |
|
|
|
1191 feed "2" "file:///dev/null_fail" |
|
|
|
1192 feed "3" "file:///dev/null" |
|
|
|
1193 } |
|
|
|
1194 ! |
|
|
|
1195 |
|
|
|
1196 # include sfeed_update and call it in the normal way. |
|
|
|
1197 cat > "$script" <<! |
|
|
|
1198 #!/bin/sh |
|
|
|
1199 SFEED_UPDATE_INCLUDE=1 . "$SFEED_UPDATE" |
|
|
|
1200 main "\$@" |
|
|
|
1201 ! |
|
|
|
1202 |
|
|
|
1203 chmod +x "$script" |
|
|
|
1204 "$script" "$rc" >"$log_stdout" 2> "$log_stderr" |
|
|
|
1205 expect "1" "$?" "exit statuscode" |
|
|
|
1206 |
|
|
|
1207 linecount=$(wc -l < "$log_stdout") |
|
|
|
1208 linecount=$((linecount+0)) |
|
|
|
1209 expect "2" "$linecount" "2 lines should be written to stdout" |
|
|
|
1210 |
|
|
|
1211 linecount=$(wc -l < "$log_stderr") |
|
|
|
1212 linecount=$((linecount+0)) |
|
|
|
1213 expect "1" "$linecount" "1 line should be written to stderr" |
|
|
|
1214 |
|
|
|
1215 test -d "$feedpath" |
|
|
|
1216 expect "0" "$?" "directory should exist: $feedpath" |
|
|
|
1217 |
|
|
|
1218 for i in 1 2 3; do |
|
|
|
1219 f="$feedpath/$i" |
|
|
|
1220 test -f "$f" |
|
|
|
1221 expect "0" "$?" "file should exist: $f" |
|
|
|
1222 done |
|
|
|
1223 |
|
|
|
1224 rm -f "$script" |
|
|
|
1225 cleanup |
|
|
|
1226 |
|
|
|
1227 echo "test_include: test OK" >&2 |
|
|
|
1228 } |
|
|
|
1229 |
|
|
|
1230 # basic test for SFEED_UPDATE_INCLUDE=1 and config variables. |
|
|
|
1231 test_include_config_vars() { |
|
|
|
1232 init_test |
|
|
|
1233 |
|
|
|
1234 script="$(mktemp)" |
|
|
|
1235 |
|
|
|
1236 createrc > "$rc" <<! |
|
|
|
1237 sfeedpath="$feedpath" |
|
|
|
1238 maxjobs=1 |
|
|
|
1239 |
|
|
|
1240 # do not set defaults |
|
|
|
1241 _feed() { |
|
|
|
1242 printf '%s\t%s\n' "\$sfeedpath" "\$maxjobs" |
|
|
|
1243 } |
|
|
|
1244 |
|
|
|
1245 feeds() { |
|
|
|
1246 # feed <name> <feedurl> [basesiteurl] [encoding] |
|
|
|
1247 feed "1" "file:///dev/null" |
|
|
|
1248 } |
|
|
|
1249 ! |
|
|
|
1250 |
|
|
|
1251 # include sfeed_update and call it in the normal way. |
|
|
|
1252 cat > "$script" <<! |
|
|
|
1253 #!/bin/sh |
|
|
|
1254 SFEED_UPDATE_INCLUDE=1 . "$SFEED_UPDATE" |
|
|
|
1255 main "\$@" |
|
|
|
1256 ! |
|
|
|
1257 |
|
|
|
1258 chmod +x "$script" |
|
|
|
1259 "$script" "$rc" >"$log_stdout" 2> "$log_stderr" |
|
|
|
1260 expect "0" "$?" "exit statuscode" |
|
|
|
1261 |
|
|
|
1262 linecount=$(wc -l < "$log_stderr") |
|
|
|
1263 linecount=$((linecount+0)) |
|
|
|
1264 expect "0" "$linecount" "0 lines should be written to stderr" |
|
|
|
1265 |
|
|
|
1266 content="$(cat "$log_stdout")" |
|
|
|
1267 expect "$content" "$feedpath 1" "config values are invalid" |
|
|
|
1268 |
|
|
|
1269 rm -f "$script" |
|
|
|
1270 cleanup |
|
|
|
1271 |
|
|
|
1272 echo "test_include_config_vars: test OK" >&2 |
|
|
|
1273 } |
|
|
|
1274 |
|
|
|
1275 # basic test for SFEED_UPDATE_INCLUDE=1 and default config values for |
|
|
|
1276 # variables. |
|
|
|
1277 test_include_config_vars_default() { |
|
|
|
1278 init_test |
|
|
|
1279 |
|
|
|
1280 script="$(mktemp)" |
|
|
|
1281 |
|
|
|
1282 createrc > "$rc" <<! |
|
|
|
1283 # do not set defaults |
|
|
|
1284 _feed() { |
|
|
|
1285 printf '%s\t%s\n' "\$sfeedpath" "\$maxjobs" |
|
|
|
1286 } |
|
|
|
1287 |
|
|
|
1288 feeds() { |
|
|
|
1289 # feed <name> <feedurl> [basesiteurl] [encoding] |
|
|
|
1290 feed "1" "file:///dev/null" |
|
|
|
1291 } |
|
|
|
1292 ! |
|
|
|
1293 |
|
|
|
1294 # include sfeed_update and call it in the normal way. |
|
|
|
1295 cat > "$script" <<! |
|
|
|
1296 #!/bin/sh |
|
|
|
1297 SFEED_UPDATE_INCLUDE=1 . "$SFEED_UPDATE" |
|
|
|
1298 main "\$@" |
|
|
|
1299 ! |
|
|
|
1300 |
|
|
|
1301 chmod +x "$script" |
|
|
|
1302 "$script" "$rc" >"$log_stdout" 2> "$log_stderr" |
|
|
|
1303 expect "0" "$?" "exit statuscode" |
|
|
|
1304 |
|
|
|
1305 linecount=$(wc -l < "$log_stderr") |
|
|
|
1306 linecount=$((linecount+0)) |
|
|
|
1307 expect "0" "$linecount" "0 lines should be written to stderr" |
|
|
|
1308 |
|
|
|
1309 content="$(cat "$log_stdout")" |
|
|
|
1310 expect "$content" "$HOME/.sfeed/feeds 16" "default config values are invalid" |
|
|
|
1311 |
|
|
|
1312 rm -f "$script" |
|
|
|
1313 cleanup |
|
|
|
1314 |
|
|
|
1315 echo "test_include_config_vars_default: test OK" >&2 |
|
|
|
1316 } |
|
|
|
1317 |
|
|
|
1318 test_normal |
|
|
|
1319 test_one_fail |
|
|
|
1320 test_tmpdir |
|
|
|
1321 test_tmpdir_cleanup |
|
|
|
1322 test_config_invocation |
|
|
|
1323 test_parameters |
|
|
|
1324 |
|
|
|
1325 test_fail_fetch |
|
|
|
1326 test_fail_convertencoding |
|
|
|
1327 test_fail_parse |
|
|
|
1328 test_fail_filter |
|
|
|
1329 test_fail_merge |
|
|
|
1330 test_fail_order |
|
|
|
1331 |
|
|
|
1332 test_nothing_to_merge |
|
|
|
1333 |
|
|
|
1334 test_override_cleanup |
|
|
|
1335 test_override_fetch |
|
|
|
1336 test_override_convertencoding |
|
|
|
1337 test_override_parse |
|
|
|
1338 test_override_filter |
|
|
|
1339 test_override_merge |
|
|
|
1340 test_override_order |
|
|
|
1341 |
|
|
|
1342 test_include |
|
|
|
1343 test_include_config_vars |
|
|
|
1344 test_include_config_vars_default |
|
|
|
1345 |
|
|
|
1346 echo "Testing SIGTERM (has some delay)..." |
|
|
|
1347 |
|
|
|
1348 # NOTE: SIGINT can't reliably be tested. |
|
|
|
1349 test_sigterm |
|