Renaming and documenting bugs.
[agg.git] / tests_usr.sh
blob33743c6b6e4f326effa055fc385d29728589472e
1 #!/bin/sh
3 FEED="agg test feed"
4 ITEM1="Item 1"
5 ITEM2="Item 2"
6 ITEM3="Item 3"
8 function agg_run()
10 cat "$1" | ./agg
11 res=$?
12 if [ $res -ne 0 ]; then
13 echo "Failed to run agg ($res)."
14 exit 1
18 function agg_fail()
20 cat "$1" | ./agg
21 res=$?
22 if [ $res -eq 0 ]; then
23 echo "Failed to fail running agg."
24 exit 1
28 function agg_clean()
30 cd "$FEED"
31 ../nomtime "rm *"
32 res=$?
33 if [ $res -ne 0 ]; then
34 echo "Failed to run agg_modify."
35 exit 1
37 cd ..
40 function cleanup()
42 rm -rf "$FEED" item "simple feed" "simple feed t" "simple feed d" "long feed" || exit 1
45 function t()
47 printf " %-32s: " "$1"
49 result=$?
50 if [ $result -ne 0 ]; then
51 echo "FAIL"
52 exit $result
53 else
54 echo "OK"
58 function test_feed_exists()
60 [ -d "$1" ] && return 0
61 return 1
64 function test_feed_empty()
66 [ `ls "$1" | wc -l` = "0" ] && return 0
67 return 1
70 function test_feed_date()
72 [ `stat -c %Y "$1"` = "$2" ] && return 0
73 return 1
76 function test_item_exists()
78 [ -f "$1" ] && return 0
79 return 1
82 function test_item_date()
84 [ `stat -c %Y "$1"` = "$2" ] && return 0
85 return 1
88 function test_item_missing()
90 [ ! -e "$1" ] && return 0
91 return 1
94 function test_item_contents()
96 # BUG: "`cat`" drops trailing \n.
97 [ "`cat \"$1\"`" = "$2" ] && return 0
98 return 1
101 #################################################################
103 function test_simple_t_feed_exists()
105 test_feed_exists "simple feed t"
106 return $?
109 function test_simple_t_item_exists()
111 test_item_exists "simple feed t/item"
112 return $?
115 function test_simple_t_item_contents()
117 test_item_contents "simple feed t/item" "item"
118 return $?
121 function test_simple_d_feed_exists()
123 test_feed_exists "simple feed d"
124 return $?
127 function test_simple_d_item_contents()
129 test_item_contents "simple feed d/item" "item"
130 return $?
133 function test_complete_feed_exists()
135 test_feed_exists "$FEED"
136 return $?
139 function test_complete_feed_empty()
141 test_feed_empty "$FEED"
142 return $?
145 function test_complete_feed_date()
147 test_feed_date "$FEED" 1286052203
148 return $?
151 function test_complete_item1_exists()
153 test_item_exists "$FEED/$ITEM1"
154 return $?
157 function test_complete_item2_exists()
159 test_item_exists "$FEED/$ITEM2"
160 return $?
163 function test_complete_item3_exists()
165 test_item_exists "$FEED/$ITEM3"
166 return $?
169 function test_complete_item1_date()
171 test_item_date "$FEED/$ITEM1" 1286052203
172 return $?
175 function test_complete_item2_date()
177 test_item_date "$FEED/$ITEM2" 1270203000
178 return $?
181 function test_complete_item3_date()
183 test_item_date "$FEED/$ITEM3" 1270119246
184 return $?
187 function test_complete_item1_contents()
189 exp="\
190 Item 1
192 Random item.
194 Link: <a href=\"/dev/random\">/dev/random</a>"
195 test_item_contents "$FEED/$ITEM1" "$exp"
196 return $?
199 function test_complete_item2_contents()
201 exp="\
202 Item 2
204 Not so random item.
206 Link: <a href=\"/dev/urandom\">/dev/urandom</a>"
207 test_item_contents "$FEED/$ITEM2" "$exp"
208 return $?
211 function test_complete_item3_contents()
213 exp="\
214 Item 3
216 No item.
218 Link: <a href=\"/dev/null\">/dev/null</a>"
219 test_item_contents "$FEED/$ITEM3" "$exp"
220 return $?
223 function test_long_feed_exists()
225 test_feed_exists "long feed"
226 return $?
229 LO=________________________________.
230 LC=________________________________
232 function test_long_item_exists()
234 test_item_exists "long feed/$LC"
235 return $?
238 function test_long_item_contents
240 test_item_contents "long feed/$LC" "$LO"
241 return $?
244 ###############################################
246 echo "Cleaning directory..."
247 cleanup
249 echo "Running agg on feed without title..."
250 agg_fail tests_titleless.rss
251 t test_item_missing
253 echo "Running agg on feed with title after items..."
254 agg_fail tests_titlelate.rss
255 t test_item_missing
257 echo "Running agg on simple feed (titles)..."
258 agg_run tests_simple_titles.rss
259 t test_simple_t_feed_exists
260 t test_simple_t_item_exists
261 t test_simple_t_item_contents
263 echo "Running agg on simple feed (descriptions)..."
264 agg_run tests_simple_descriptions.rss
265 t test_simple_d_feed_exists
266 t test_simple_d_item_contents
268 echo "Running agg on missing directory..."
269 agg_run tests.rss
270 t test_complete_feed_exists
271 t test_complete_feed_date
272 t test_complete_item1_exists
273 t test_complete_item2_exists
274 t test_complete_item3_exists
275 t test_complete_item1_date
276 t test_complete_item2_date
277 t test_complete_item3_date
278 t test_complete_item1_contents
279 t test_complete_item2_contents
280 t test_complete_item3_contents
282 echo "Running agg on up-to-date directory..."
283 agg_run tests.rss
284 t test_complete_feed_exists
285 t test_complete_feed_date
286 t test_complete_item1_exists
287 t test_complete_item2_exists
288 t test_complete_item3_exists
289 t test_complete_item1_date
290 t test_complete_item2_date
291 t test_complete_item3_date
292 t test_complete_item1_contents
293 t test_complete_item2_contents
294 t test_complete_item3_contents
296 echo "Deleting old news..."
297 agg_clean
298 t test_complete_feed_exists
299 t test_complete_feed_date
300 t test_complete_feed_empty
302 echo "Running agg on clean up-to-date directory..."
303 agg_run tests.rss
304 t test_complete_feed_exists
305 t test_complete_feed_date
306 t test_complete_feed_empty
308 echo "Changing mtime..."
309 touch -md "1970-01-01 00:00:00.000000000 +0000" "$FEED"
311 echo "Running agg on clean outdated directory..."
312 agg_run tests.rss
313 t test_complete_feed_exists
314 t test_complete_feed_date
315 t test_complete_item1_exists
316 t test_complete_item2_exists
317 t test_complete_item3_exists
318 t test_complete_item1_date
319 t test_complete_item2_date
320 t test_complete_item3_date
321 t test_complete_item1_contents
322 t test_complete_item2_contents
323 t test_complete_item3_contents
325 echo "Running agg on feed with long items..."
326 agg_run tests_long.rss
327 t test_long_feed_exists
328 t test_long_item_exists
329 t test_long_item_contents
331 echo "Success! Cleaning up..."
332 cleanup