2 # Copyright (C) 2011 Andreas Waidler <arandes@programmers.at>
4 # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
5 # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7 # 0. You just DO WHAT THE FUCK YOU WANT TO.
20 if [ $res -ne 0 ]; then
21 echo "Failed to run agg ($res)."
22 FAILURES
=`expr $FAILURES + 1 `
30 if [ $res -eq 0 ]; then
31 echo "Failed to fail running agg."
32 FAILURES
=`expr $FAILURES + 1 `
38 find "$FEED" -type f
-exec ..
/src
/nomtime
rm '{}' \
;
40 if [ $res -ne 0 ]; then
41 echo "Failed to run nomtime."
42 FAILURES
=`expr $FAILURES + 1 `
48 rm -rf "$FEED" item
"feed" "simple feed" "simple feed t" "simple feed d" "long feed" ||
exit 1
53 printf " %-32s: " "$1"
56 if [ $result -ne 0 ]; then
58 FAILURES
=`expr $FAILURES + 1 `
64 function test_feed_exists
() { [ -d "$1" ]; }
65 function test_feed_empty
() { [ `ls "$1" | wc -l` = "0" ]; }
66 function test_feed_date
() { [ `stat -c %Y "$1"` = "$2" ]; }
67 function test_item_exists
() { [ -f "$1" ]; }
68 function test_item_date
() { [ `stat -c %Y "$1"` = "$2" ]; }
69 function test_item_missing
() { [ ! -e "$1" ]; }
70 # BUG: "`cat`" drops trailing \n.
71 function test_item_contents
() { [ "`cat \"$1\"`" = "$2" ]; }
73 ################## TEST CASES FOLLOW ######################
75 function test_simple_t_feed_exists
() { test_feed_exists
"simple feed t"; }
76 function test_simple_t_item_exists
() { test_item_exists
"simple feed t/item"; }
77 function test_simple_t_item_date
() { test_item_date
"simple feed t/item" 0; }
78 function test_simple_t_item_contents
() { test_item_contents
"simple feed t/item" "item"; }
80 function test_simple_d_feed_exists
() { test_feed_exists
"simple feed d"; }
81 function test_simple_d_item_contents
() { test_item_contents
"simple feed d/item" "item"; }
83 LO
=________________________________________________________________.
84 LC
=_____________________________________________________________...
85 function test_long_feed_exists
() { test_feed_exists
"long feed"; }
86 function test_long_item_exists
() { test_item_exists
"long feed/$LC"; }
87 function test_long_item_contents
{ test_item_contents
"long feed/$LC" "$LO"; }
89 function test_complete_feed_exists
() { test_feed_exists
"$FEED"; }
90 function test_complete_feed_empty
() { test_feed_empty
"$FEED"; }
91 function test_complete_feed_date
() { test_feed_date
"$FEED" 1286052203; }
92 function test_complete_item1_exists
() { test_item_exists
"$FEED/$ITEM1"; }
93 function test_complete_item2_exists
() { test_item_exists
"$FEED/$ITEM2"; }
94 function test_complete_item3_exists
() { test_item_exists
"$FEED/$ITEM3"; }
95 function test_complete_item1_date
() { test_item_date
"$FEED/$ITEM1" 1286052203; }
96 function test_complete_item2_date
() { test_item_date
"$FEED/$ITEM2" 1270203000; }
97 function test_complete_item3_date
() { test_item_date
"$FEED/$ITEM3" 1270119246; }
98 function test_complete_item1_contents
()
105 Link: <a href=\"/dev/random\">/dev/random</a>"
106 test_item_contents
"$FEED/$ITEM1" "$exp"
108 function test_complete_item2_contents
()
115 Link: <a href=\"/dev/urandom\">/dev/urandom</a>"
116 test_item_contents
"$FEED/$ITEM2" "$exp"
118 function test_complete_item3_contents
()
125 Link: <a href=\"/dev/null\">/dev/null</a>"
126 test_item_contents
"$FEED/$ITEM3" "$exp"
128 function test_fail_item_missing
() { test_item_missing
"feed/item"; }
130 ###############################################
132 echo "Running agg on simple feed (titles)..."
134 t test_simple_t_feed_exists
135 t test_simple_t_item_exists
136 t test_simple_t_item_date
137 t test_simple_t_item_contents
140 echo "Running agg on simple feed (descriptions)..."
142 t test_simple_d_feed_exists
143 t test_simple_d_item_contents
146 echo "Running agg on sample feed (directory missing)..."
148 t test_complete_feed_exists
149 t test_complete_feed_date
150 t test_complete_item1_exists
151 t test_complete_item2_exists
152 t test_complete_item3_exists
153 t test_complete_item1_date
154 t test_complete_item2_date
155 t test_complete_item3_date
156 t test_complete_item1_contents
157 t test_complete_item2_contents
158 t test_complete_item3_contents
160 echo "Running agg sample feed (up to date) ..."
162 t test_complete_feed_exists
163 t test_complete_feed_date
164 t test_complete_item1_exists
165 t test_complete_item2_exists
166 t test_complete_item3_exists
167 t test_complete_item1_date
168 t test_complete_item2_date
169 t test_complete_item3_date
170 t test_complete_item1_contents
171 t test_complete_item2_contents
172 t test_complete_item3_contents
174 echo "Deleting old news..."
176 t test_complete_feed_exists
177 t test_complete_feed_date
178 t test_complete_feed_empty
180 echo "Running agg on sample feed (directory up to date but empty)..."
182 t test_complete_feed_exists
183 t test_complete_feed_date
184 t test_complete_feed_empty
186 echo "Changing mtime..."
187 touch -md "1970-01-01 00:00:00.000000000 +0000" "$FEED"
189 echo "Running agg on sample feed (directory outdated and empty)..."
191 t test_complete_feed_exists
192 t test_complete_feed_date
193 t test_complete_item1_exists
194 t test_complete_item2_exists
195 t test_complete_item3_exists
196 t test_complete_item1_date
197 t test_complete_item2_date
198 t test_complete_item3_date
199 t test_complete_item1_contents
200 t test_complete_item2_contents
201 t test_complete_item3_contents
204 echo "Running agg on feed with long items..."
206 t test_long_feed_exists
207 t test_long_item_exists
208 t test_long_item_contents
211 echo "Running agg on feed without title..."
212 agg_fail no_feed_title.rss
213 t test_fail_item_missing
215 echo "Running agg on feed with title after items..."
216 agg_fail feed_title_after_items.rss
217 t test_fail_item_missing
219 echo "Running agg on feed with item title after description..."
220 agg_fail title_after_description.rss
221 t test_fail_item_missing
224 echo "Failed $FAILURES times!"